Use member function at() to : string at « string « C++ Tutorial






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

int main()
{
   string s1( "cat" ), s2, s3;

   s2 = s1;          
   s3.assign( s1 );  
   cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: "
        << s3 << "\n\n";

   // demonstrating member function at()
   int len = s3.length();
   for ( int x = 0; x < len; ++x ) 
      cout << s3.at( x );

   return 0;
}








15.4.string at
15.4.1.Demonstrating member function at
15.4.2.Use member function at() to