C++ – Strings

Inizialization


...
string mystring = "This is a string";
string mystring ("This is a string");
string mystring {"This is a string"};
...

Basic Statement


// include standard input and output operations
#include <iostream>
// include strings
#include <string>
using namespace std;

int main ()
{
  string mystring;
  mystring = "This is the initial string content";
  // character output - variable - end line
  cout << mystring << endl;
  mystring = "This is a different string content";
  cout << mystring << endl;
  return 0;
}

Escape Codes

\n newline
\r carriage return
\t tab
\v vertical tab
\b backspace
\f form feed (page feed)
\a alert (beep)
\’ single quote (‘)
\” double quote (“)
\? question mark (?)
\\ backslash (\)