博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
比较fscanf 和getline读取文件效率
阅读量:4286 次
发布时间:2019-05-27

本文共 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/

你可能感兴趣的文章
论文笔记 | Does Structure Matter? Encoding Documents for Machine Reading Comprehension
查看>>
论文笔记|Self-Supervised Test-Time Learning for Reading Comprehension
查看>>
论文笔记|Open-world Learning and Application to Product Classification
查看>>
论文笔记 _ ELECTRA_ Pre-training Text Encoders as Discriminators Rather than Generators
查看>>
【论文笔记】
查看>>
论文笔记:Exploring Pre-trained Language Models for Event Extraction and Generation
查看>>
论文解读 | QANET: COMBINING LOCAL CONVOLUTION WITH GLOBAL SELF-ATTENTION FOR READING COMPREHENSION
查看>>
linux 安装nginx
查看>>
linux 搭建rocketmq集群
查看>>
linux 安装zookeeper集群
查看>>
RocketMq单机安装(Windows)
查看>>
Windows 上安装 MySQL
查看>>
eclipse 的mybatis中mapper.xml文件标签没有提示的解决方法
查看>>
linux 上一主两从mysql集群中某台数据库宕机解决方法
查看>>
大牛面试指南
查看>>
android入门(一)---UI组件之文本框(TextView)
查看>>
演示动画怎么实现的
查看>>
android入门---Activity组件.活动(一)
查看>>
Android入门---GridView组件
查看>>
获取apk文件上的精美图片素材
查看>>