本文共 507 字,大约阅读时间需要 1 分钟。
#include#include #include #include #include #include using namespace std;class data{public: int src; int dest; long weight;};//行的类定义int main(){ vector incsv; data intp; //第一种方法读取文件 FILE *fp; clock_t begin=clock(); fp=fopen("graph.txt","r");//文件路径 while(1){ fscanf(fp,"%d %d %ld",&intp.src,&intp.dest,&intp.weight); incsv.push_back(intp); if (feof(fp))break; } fclose(fp); cout<<"time="<
结果是使用getline更快一些,600万条的数据使用0.9秒
转载地址:http://ssxgi.baihongyu.com/