Inside a loop I do some calculations and then I want to print a string value from a byte array, once the loop is done print a new line.
Using fmt.Print will allocate a buffer, but all I want to do is print the character to stdout. Is there a way to do that?
for i, i < size; i++ {
b = a[i] + i * 10
fmt.Print(string((b)))
}
fmt.Println()
You can do this by simply writing to the os.Stdout file:
var buff [1]byte
for i, i < size; i++ {
b = a[i] + i * 10
buff[0] = b
os.Stdout.Write(buff[:])
}
buff[0] = '\n'
os.Stdout.Write(buff[:])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With