C++学习记录之string输出

代码:

#include<iostream>
using namespace::std;
int main(void)
{
string str("abcdefg");
cout << str << endl;
cout << str.c_str() << endl;
cout << str[0] << endl;
cout << str[2] << endl;
cout << str[23] << endl;    //over
cout << str.at(3) << endl;
//cout << str.at(23) << endl;   //over
try    //solve over
{
   str.at(23);
}
catch(...)
{
   cout << "over" << endl;
}
return 0;
}
运行结果:

C++学习记录之string输出

 

相关文章: