std::ifstream fout;
int length;
fout.open("test.txt");
fout.seekg(0,std::ios::beg);//文件指针指向结尾
length=in.tellg;//获取文件长度
fout.seekg(0,std::ios::beg);//文件指针从新指向开头
char *buffer=new char[length];
fout.read(buffer,length);//读取
in.close();
本文介绍了一个使用C++进行文件操作的例子,包括打开文件、定位到文件开头以获取文件长度、重新定位并读取整个文件内容的过程。
std::ifstream fout;
int length;
fout.open("test.txt");
fout.seekg(0,std::ios::beg);//文件指针指向结尾
length=in.tellg;//获取文件长度
fout.seekg(0,std::ios::beg);//文件指针从新指向开头
char *buffer=new char[length];
fout.read(buffer,length);//读取
in.close();
2973

被折叠的 条评论
为什么被折叠?