string类简述
#incldue <iostream>
#include <string>
using namespace std;
void main() {
string s1("Hello");
cout << s1 << endl;
string s2(8, 'x');
cout << s2 << endl;
string month = "March";
cout << month << endl;
string s;
s = 'n';
cout << x << endl;
}
/* 输出
Hello
xxxxxxxx
March
n
*/
- 长度用成员函数
length()
读取string的赋值和连接
比较string
求子串
交换string
查找string中的字符
删除string中的字符
替换string中的字符
在string中插入字符
将string转换为char*
string拷贝
字符串流处理
输入流 istringstream
```cpp string input(“Input test 123 4.7 A”); istringstream inputString(input); string string1, string2; int i; double d; char c; inputString >> string1 >> string2 >> i >> d >> c; cout << string1 << endl << string2 << endl; cout << i << endl << d << endl << c <<endl;
long L; if(inputString >> L) cout << “long\n”; else cout << “empty\n”; / 输出 Input test 123 4.7 A empty /
<a name="Yg06Z"></a>
### 输出流 ostringstream
```cpp
ostringstream outputString;
int a = 10;
outputString << "This " << a << "ok" << endl;
cout << outputString.str();
/* 输出
This 10ok
*/