读书人

read函数读取整个文本文件的例子多谢

发布时间: 2013-01-09 09:38:15 作者: rapoo

求一个read函数读取整个文本文件的例子,谢谢
网上找了半天也没找到一个可以编译通过的

read读取整个文本文件,大约80M
并保存到字符串数组,谢谢a
[解决办法]
不难吧,试试这个,刚刚手敲的


#include <string>
#include <fstream>
#include <iostream>
using namespace std;

void main()
{
string str = "";
char tmp,filename[30];

cout<<"Please input file's name: ";
cin>>filename;
ifstream ifile(filename);
if (ifile.good())
{
while (ifile.get(tmp))
{
str += tmp;
}
//cout<<str<<endl;
}
ifile.close();
}

[解决办法]
这个很难吗?对于普通文件直接读进来就行了
char buf[80 * 1024 * 1024]
read(fd, buf, sizeof(buf));

如果不放心可以用unp上的readn

读书人网 >C语言

热点推荐