例如:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
int num = 10;
string str;
stringstream toString;
toString << num;
toString >> str;
cout << str << "\n"; //10
int num2 = 20;
string str2;
toString << num2;
toString >> str2;
cout << str2 << "\n"; //str2 is empty
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道我必须清除这个:
toString.str("");
toString.clear();
Run Code Online (Sandbox Code Playgroud)
但是为什么在使用运算符后它不会自动清除>>?
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |