c++读取文本文件最高效的方法
来源:互联网 发布:淘宝信用贷款影响大吗 编辑:程序博客网 时间:2024/05/29 05:52
从网上找到的方法,可以一下子读取文件的所有内容到字符串中,实验了很有用,发出来共享。
/*
* main.cpp
*
* Created on: 2014年6月17日
* Author: Spike
*/
/eclipse cdt, gcc 4.8.1/
include
include
include
include
std::string get_file_contents(const char *filename)
{
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}
throw(errno);
}
int main (void)
{
std::cout << get_file_contents(“跳河的兔子.txt”) << std::endl;
return 0;
}
0 0
- c++读取文本文件最高效的方法
- 读取文本文件的最常用方法
- C#高效的读取大型文本文件的方法
- 【C++】读取整个文本文件的方法
- Java中最高效的读取字节文件的方法
- C语言求素数/质数最高效的方法
- C++:文本文件的读取和输入
- C/C++逐行读取文本文件的数据
- UNICODE环境下整行读取文本文件的方法
- C#读取txt文本文件(dat)的方法
- python读取文本文件数据的方法总结
- readbuffer的readline方法读取文本文件bug
- objective-c 读取文本文件
- C#_StreamReader读取文本文件
- TensorFlow高效读取数据的方法
- TensorFlow高效读取数据的方法
- TensorFlow高效读取数据的方法
- TensorFlow高效读取数据的方法
- 如何阅读一本书----你的阅读方式有问题吗?
- 有关DataTable的相关操作
- [生存志] 第48节 叔向忧羊舌
- Mysql启动失败
- php array_push 与 $arr[]=$value 性能比较
- c++读取文本文件最高效的方法
- MyBatis Generator 配置
- html富文本框:kindeditor
- CF704A
- MTK 6735平台 高温停止充电问题总结
- Hadoop - 任务调度系统比较
- 编译tomcat7
- 科技论文写作流程及注意
- 如何在Github上为开源项目贡献自己的代码