// vistor_string.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
int _tmain()
{
using namespace std;
string strSTLString("Hello String");
cout << "Displaying characters using array-syntax:"<<endl;
for( size_t nCharCounter = 0 ; nCharCounter < strSTLString.length() ; nCharCounter++)
{
cout <<"Character ["<<nCharCounter<<"] is :";
cout <<strSTLString[nCharCounter]<<endl;
}
cout<<endl;
cout<< "Displaying characters using iterators:"<<endl;
int nCharOffset = 0 ;
string::const_iterator iCharacterLocator;
for( iCharacterLocator = strSTLString.begin();
iCharacterLocator != strSTLString.end();
++iCharacterLocator )
{
cout<<"Character ["<<nCharOffset++<<"] is :";
cout<<*iCharacterLocator<<endl;
}
cout<<endl ;
cout<<" The char* representation of the string is :";
cout<<strSTLString.c_str()<<endl;
getchar();
return 0;
}