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'也會吞下換行符。 –