Skip to main content

2.10) Strings In C++


string target = "World";
string message = "Hello " + target + "!";
cout << message << endl;
cout << message[6] << endl;
  • Use string to represent a sequence of characters (or wstring for wide characters)
  • Remember to add #include <string> to your program!
  • Literal strings are delimited by the double quote character, ", not the single quote
  • Strings can be concatenated using + and += operators
  • Individual characters can be accessed using [] and an integer index (0 for the first character)