stringstream sstream
https://www.acwing.com/activity/content/code/content/1970131/
stringstream用法 https://www.acwing.com/blog/content/5756/
#include <iostream>
#include <sstream>
using namespace std;
int main() {
stringstream ss;
ss << "string" <<" stream";
cout << ss.str();
ss.str("");
ss << "another string";
cout << ss.str();
return 0;
}
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
string src("Avatar 123 5.2 Titanic Kv");
istringstream istrStream(src); // 建立src到istrStream的联系
string s1,s2;
int n;
double d;
char c;
istrStream >> s1 >> n >> d >> s2 >> c; // 把src的内容当做输入流进行读取
ostringstream ostrStream;
ostrStream << s1 << endl << s2 << endl << n << endl << d << endl << c <<endl;
cout << ostrStream.str();
return 0;
}
程序的输出结果:
Avatar
Titanic
123
5.2
K
sscanf
https://www.acwing.com/file_system/file/content/whole/index/content/3279316/
sscanf函数用法详解 https://blog.csdn.net/zhouwei1221q/article/details/44890617
sprintf
int myint;
char buf[SIZE];
sprintf(buf, “my data is %d”, myint);
其他
https://www.acwing.com/blog/content/550/
C++中 string类字符串和数字的转化有简便方法
https://www.acwing.com/blog/content/1882/
string str = "89";
int i = stoi(str);
cout << i;
以stringstream类为中间介质,来实现字符串于数字的转化
https://www.acwing.com/blog/content/2267/
C++11中的string - to_string/stoi
https://blog.csdn.net/gao1440156051/article/details/50729691