#include <iostream>
#include <string>
using namespace std;

int main(int argc, char** argp, char** envp)
{

  // Here are three equivalant ways to define a std::string from
  // a string literal according to the language standard. 
  
  string str01("The quick brown fox jumped over the lazy dogs");

  string str02 = "The quick brown fox jumped over the lazy dogs";

  string str03 = string("The quick brown fox jumped over the lazy dogs");

  // The same constructior is called in each instance. The second 
  // and third statements are idiomatic because the assignment 
  // operator is not called.
  
  cout << str01 << '\n';      // This does not flush cout and is
                              // therefore more efficient than
  cout << str02 << endl;      // this line, which flushes cout.

  cout << str03 << '\n';      

  cout.flush();               // Explicitly flushes cout.
  
  
  // The following are roughly equivalent to each other but not to the
  // above.  Here the strings are first initialized as null strings by 
  // the default constructor and then the assignment operator destroys 
  // the string and replaces it with another.

  { // Scope: Because of these braces ..

    string str04, str05, str06;
  
    str04 = str01;
  
    str05 = string("The quick brown fox jumped over the lazy dogs");
  
    str06 = "The quick brown fox jumped over the lazy dogs";
  
    cout << str04 << '\n' << str05 << '\n' << str06 << '\n';
  
  } // ... the variables str04, str05, str06 have been deleted and can no
    // longer be used without re-definition.

  string str06;    // str06 is re-defined here
  
  // Strings can be added

  str06 = str03 + string("\n") + string("How now brown cow?") + string("\n");

  cout << str06;

  // A string of given length can be constructed with a fill character.

  string str07(40,'*');

  // Elements can be changed, but BE WARNED, the first element is 
  // str07[0] and the last is str08[39].  An out of range access 
  // will cause the program to abort.

  str07[0] = 'H'; str07[1] = 'o'; str07[2] = 'w';
  str07[4] = 'a'; str07[5] = 'r'; str07[6] = 'e';
  str07[8] = 'y'; str07[9] = 'o'; str07[10] = 'u'; str07[11] = '?';

  cout << str07 << '\n';
  
  return 0;
}
