1. 程式人生 > >【常用】檔案中的字元一個一個流出來

【常用】檔案中的字元一個一個流出來

string getFileContext(const string& filename)
{
string str;
str.clear();
char buf[1024];
char *p;
p = buf;
memset(buf, 0, 1024);
ifstream in;
in.open(filename);
while ((*p = in.get()) != EOF)
{
p++;
}
cout << “Buf” << endl;
puts(buf);
str += buf;
cout << str << endl;
in.close();
return str;
}