I am trying to make a global byte array from a string with:
var operators = []byte {"+-*/%"}
however, I am getting the error
cannot use string("+-*/") (type untyped string) as type byte in array or slice literal
What am I doing wrong here?
Use a type conversion to convert a string to a slice of bytes. Note the use of ()
instead of {}
.
var operators = []byte("+-*/%")
The code in the question is a composite literal.
Try doing something like this instead
var operators = []byte("Hello World")
In your code you are trying to literally put a string inside of a byte array as a member, you cannot do that. The error helps you out a bit here by saying it can't use your string as type byte (because it isn't a byte, it is a string).