1、string定义:
2、输入详细用法:
注:1、读取C风格字符串的函数(getline与<<
)是istream类的方法,读取string是独立的函数。
2、当使用指定字符如':'
作为字符串截取边界时,原'\n'
字符被当成普通字符。
3、常用函数:字符统计、返回C风格字符串:
string a = "abcnde";
// 以下两方法都可以统计,由于类库版本早晚问题保留了两个统计函数。
int count1 = a.size();
int count1 = a.length();
//转换为c风格字符串
char * b = a.c_string();
注:
本文供使用时查找,具体详细用法见C++ Primer Plus 16.1节。