C++ C++;fstream读取和写入同一文件
下面是一个简单的程序,在文件末尾写一个换行符,包含每行开始的相对位置 代码: 然而,预期的内容是:C++ C++;fstream读取和写入同一文件,c++,fstream,C++,Fstream,下面是一个简单的程序,在文件末尾写一个换行符,包含每行开始的相对位置 代码: 然而,预期的内容是: abcd efg hi j 5 9 12 14 (there is a blank line at the end of the file) 似乎while条件中的getline首先将abcd读入行,然后将一系列空字符串读入行 请帮忙 [编辑] 环境:Win7,eclipseforc++,Mingw(g++version4.7.2)我在VS2012和g++上试过你的代码,它们都给了我预期的结果
abcd
efg
hi
j
5 9 12 14
(there is a blank line at the end of the file)
似乎while条件中的getline
首先将abcd
读入行
,然后将一系列空字符串读入行
请帮忙
[编辑]
环境:Win7,eclipseforc++,Mingw(g++version4.7.2)我在VS2012和g++上试过你的代码,它们都给了我预期的结果591214
。然而,我不明白为什么它对你不起作用。
abcd
efg
hi
j
5 6 7 8
(there is a blank line at the end of the file)
abcd
efg
hi
j
5 9 12 14
(there is a blank line at the end of the file)