0. 头文件和命名空间
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
1. 实现
使用opencv时,方便地读取带有编号的图片
int main(){
string path = "C:/imgs/";
stringstream stm;
string temppath;
vector<string>imgspath;
for (int i = 1; i < 10; i++)
{
stm << i;
stm >> temppath;
path = path + temppath + ".jpg";
cout << path << endl;
imgspath.push_back(path);
path = "C:/imgs/";
// stm中的数据清空后才可以写入数据
stm.clear();
}
return 0;
}
2. 读取更多数据
int main(){
// 当想在stringstream中存放更多的内容时,可以一次性输入
string s1 = "hello ";
string s2 = " wor