你好,文件流一个个读取字符可以使用ifstream对象的get函数,读取文件一行内容可使用getline函数。示例如下:
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;
}
希望能够帮到你。