read函数读取整个文本文件的例子,多谢
求一个read函数读取整个文本文件的例子,谢谢
网上找了半天也没找到一个可以编译通过的
read读取整个文本文件,大约80M
并保存到字符串数组,谢谢a
------解决方案--------------------
不难吧,试试这个,刚刚手敲的
------解决方案--------------------
这个很难吗?对于普通文件直接读进来就行了
char buf[80 * 1024 * 1024]
read(fd, buf, sizeof(buf));
如果不放心可以用unp上的readn
网上找了半天也没找到一个可以编译通过的
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