【发布时间】:2014-03-21 01:20:37
【问题描述】:
我很难找出为什么我不能使用 fstream get 函数读取所有字符。 我的代码如下:
ifstream input_stream(input_filename.c_str(), ios::in);
string input;
if(input_stream)
{
char character;
while(input_stream.get(character))
{
input += character;
}
input_stream.close();
}
else
cerr << "Error" << endl;
通过一些测试,我发现当 character = 26(ASCII 中的 SUB)时出现问题,因为 input_stream.get(26) 返回 false 并且我退出了 while 循环。 我想在我的字符串中输入文件中的所有字符,包括 SUB。 我一开始尝试使用 getline 函数,但遇到了类似的问题。 你能帮我吗?
【问题讨论】:
-
在哪个操作系统上?
-
必须是 Windows - 亲爱的老 control-z 又来了。
标签: c++ ascii ifstream getline substitution