You do not have the correct core concepts right, and should probably work through some C++ tutorials or courses before writing a program like this.
A few things:
- The ± symbol is a unicode character.
char
in C++ refers to a single byte, usually an ASCII value if it's referring to text data. So it can't store the unicode +- symbol. Instead, you can store this unicode value in an std::string buttons[4][4];
(although the full answer is much more complicated).
- In C++,
'a'
refers to the character a, but "a"
refers to a const char*
. If it wasn't for the unicode issue, you should have used single quotes.
- You try to assign to
Buttons[1]
, but buttons is a 2-dimensional array. The element 1 also refers to the second element of the array, which may not be what you intended. Instead you could write Buttons[0][0]='a';
- You don't have the concept of a member function/member variable down. The proper way to do this would be to have an initializer function and then call it.
Here is a fixed/working example, but I really recommend going through other tutorials first!
#include <iostream>
#include <string>
struct Interface {
std::string buttons[4][4];
void initialize_interface() {
buttons[0][0] = std::string("\u00B1");
std::cout << buttons[0][0] << std::endl;
}
};
int main() {
Interface my_interface;
my_interface.initialize_interface();
return 0;
}
As M.M. notes in the comments, a more paradigmatic approach would be the following:
#include
#include
struct Interface {
std::string buttons[4][4];
Interface() {
buttons[0][0] = std::string("\u00B1");
std::cout << buttons[0][0] << std::endl;
}
};
int main() {
Interface my_interface;
return 0;
}
Interface::Interface
is called the constructor, and it runs upon initialization.