Display the characters in a string one at a time by using the indexing operator : string at « String « C++






Display the characters in a string one at a time by using the indexing operator

  
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string str1("A");
  string str2("B");
  string str3("G");
  string str4;

  cout << "  str1: " << str1 << endl;
  cout << "  str2: " << str2 << endl;
  cout << "  str3: " << str3 << "\n\n";

  for(unsigned i = 0; i < str1.size(); ++i)
    cout << "str1[i]: " << str1[i] << endl;
  cout << endl;

  return 0;
}
  
    
  








Related examples in the same category

1.Demonstrating member function at
2.Get a C-Style String from a C++ String
3.Accessing Character Elements of an STL String