So, my array looks like this:
string links[26][4];
links[0][0] = 'A';
links[0][1] = 'WOL-LA-CHEE';
And if I try to print let's say 'WOL-LA-CHEE' like this:
cout << links[0][1]
my output looks like this:
E
What am I doing wrong?
So, my array looks like this:
string links[26][4];
links[0][0] = 'A';
links[0][1] = 'WOL-LA-CHEE';
And if I try to print let's say 'WOL-LA-CHEE' like this:
cout << links[0][1]
my output looks like this:
E
What am I doing wrong?
If you put text between single quotes, that denotes a character literal. Since there are copy constructors for std::string
from char
and const char *
, this works for one character, but it doesn't do what you think it does for multiple characters. You most likely want to put the strings between double quotes:
links[0][1] = "WOL-LA-CHEE";
Put the string in double quotes. "WOL-LA-CHEE"
. Single quotes declare a character constant, whose value is unspecified in this case.
'WOL-LA-CHEE'
is a multicharacter literal. It has implementation-defined value and is an int
. It seems that you want a string literal instead:
links[0][0] = "A";
links[0][1] = "WOL-LA-CHEE";
Assigning 'A'
worked previously because this is a normal character literal and has type char
. std::string
has an overload of operator=
that takes a char
.