C++实现文件按行读取后分割getline
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
using namespace std;
template<typename out_type, typename in_value>
out_type convert(const in_value & t)
{
stringstream stream;
stream<<t;//向流中传值
out_type result;//这里存储转换结果
stream>>result;//向result中写入值
return result;
}
int main()
{
string s = "Hello World! Hello World";
stringstream ss;
ss<<s;
while(ss>>s)
{
cout<<s<<endl;
string val = convert<string>(s);
cout<<val<<endl;
}
return 0;
}