// string.cpp - Clase string
#include <iostream>
#include <string>
using namespace std;

int main( )
{
/*
  char cadena[40]; // matriz de 40 caracteres
  cout << "cadena: "; cin.getline(cadena, 40, '\n');
  // ...
  string str(cadena);
  cout << "Texto introducido: " << str << endl;

  string::reverse_iterator e; // e es un iterador
  for (e = str.rbegin(); e != str.rend(); e++)
    cout << *e; // mostrar la cadena en orden inverso

  string str1 = "abcdefgh";
  char car = str1[2]; // car = 'c'
  car = str1.at(2); // car = 'c'

  string str1 = "abcdefgh";
  string str2, str3, str4;
  str2 = str1;             // o bien: str2.assign(str1);
  str2[2] = 'x';
  str3 = "xyz";            // o bien: str3.assign("xyz");
  str4 = 'c';              // o bien: str4.assign(sizeof(char), 'c');

  string str1 = "abcdefgh";
  const char* cadena1 = str1.c_str(); // aņade '\0'
  const char* cadena2 = str1.data();  // no aņade '\0'
  char cadena[80];
  str1.copy(cadena, str1.length(), 0);

  string str1 = "abcde", str2 = "Abcdefg";
  if (str1 < str2) // si str1 es menor que str2 ...
    cout << str1 << endl;
  else
    cout << str2 << endl;

  string str1 = "abcd";
  string str2 = "lmn";
  string str3 = "efg";
  str1 += str2;                      // str1 = "abcdlmn"
  str1.insert(4, "ijk");             // str1 = "abcdijklmn"
  str1.insert(4, str3);              // str1 = "abcdefgijklmn"
  str1.insert(7, sizeof(char), 'h'); // str1 = "abcdefghijklmn"

  string str1 = "abcd";
  string str2 = "lmn";
  string str3 = str1 + str2;

  int pos;
  string str1 = "abcdefgh";
  pos = str1.find("xxx");              // pos = 4
  cout << pos << endl;
  if (pos == string::npos) cout << "no\n" << endl;
  pos = str1.rfind("efg");             // pos = 4
  pos = str1.find_first_of("gfe");     // pos = 4
  pos = str1.find_last_of("gfe");      // pos = 6
  pos = str1.find_first_not_of("efg"); // pos = 0
  pos = str1.find_last_not_of("efg");  // pos = 7

  string str1 = "abc def gh";
  str1.replace(str1.find("de"), 2, "vwxyz"); // str1 = abc vwxyzf gh

  string str1 = "abc defgh ijk";
  string str2 = str1.substr(5, 4); // str2 = "efgh"

  int ncars, capacidad;
  string str1 = "abc defgh ijk";
  capacidad = str1.capacity();    // capacidad = 13
  ncars = str1.length();          // ncars = 13
  str1.resize(str1.length() * 2); // str1 = "abc defgh ijk"
  str1 = "xyz";                   // str1 = "xyz"
  capacidad = str1.capacity();    // capacidad = 26
  ncars = str1.length();          // ncars = 3
*/
  string str;

  cout << "Texto: ";
  getline(cin, str);   // entrada: aaa bbb
  cout << str << endl; // salida:  aaa bbb

  cout << "Texto: ";
  cin >> str;          // entrada: aaa bbb
  cout << str << endl; // salida:  aaa

  cout << endl;
  system("pause");
}

