33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream fileIn;
char* buff;
long size;
fileIn.open("testIO.cpp",ios::binary|ios::in|ios::ate|ios::_Nocreate);
if(!fileIn){
cout << "open file err" << endl;
system("pause");
return -1;
}
size = fileIn.tellg();
buff = new char[size];
fileIn.seekg(0,ios::beg);
fileIn.read(buff,size);
cout << buff << endl;
fileIn.close();
system("pause");
}
...
buff = new char[size + 1];
fileIn.seekg(0,ios::beg);
fileIn.read(buff,size);
buff[size] = '\0';
...