0
我有一个文件,格式如下:读取字符
# This is one comment
# Another comment
但问题是运行下面的代码时:
char c;
string string1;
while ((c = fgetc(file)) == '#') {
string1 += c;
while ((c = fgetc(file)) != '\n') {
string1 += c;
}
}
输出是:
# This is one comment# Another comment
我知道在第一次评论中的'\ n'并没有保存在string1中,但是我怎样才能用这种方法或类似方法解决呢?
使用['std :: getline'](http://en.cppreference.com/w/cpp/string/basic_string/getline) – pyon
该代码没有输出,也不完全清楚你想要的输出成为。 – RichardPlunkett
@EduardoLeón - 'getline'也会吞下换行符。 –