50w行运行时间1s(好像和vector关系不大
代码:
#include<iostream>#include<fstream>#include<sstream>#include<vector>#include<string>
int main(){ std::ofstream outfile("row2.txt",std::ios::out); std::ifstream infile("data.txt",std::ios::in);
std::vector<std::string> vect; std::string line(""); int row=2; while(std::getline(infile,line)){ std::istringstream stream(line); std::string temp(""); for(int i=0;i<row;i++){ stream>>temp; } // vect.push_back(temp); outfile<<temp<<"\n"; } infile.close(); outfile.close(); return 0;}
代码截图:
数据生成:
时间测量:
结果: