-1

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?

paradajz
  • 11
  • 1

3 Answers3

5

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";

Stuff to read about multicharacter literals.

Community
  • 1
  • 1
2

Put the string in double quotes. "WOL-LA-CHEE". Single quotes declare a character constant, whose value is unspecified in this case.

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122
2

'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.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324