读书人

g++的有关问题,还是?不懂。

发布时间: 2012-02-12 17:16:33 作者: rapoo

g++的问题,还是?不懂。。。
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
ifstream out( "t.txt ");
string line;
int i = 0;
while(1)
{
if(out.eof())
break;
out > > line ;
cout < < line < < " ";

}//while(!out.eof());

return 0;
}

t.txt 内容为Hello,world! I hope I can succeed!
输出却为Hello,world! I hope I can succeed! succeed!(succeed重复了两次!)
在dev_c++却输出正常。。。
问了几个人,他们的g++都运行正确,为什么?
这问题可以怎么解决呢?

谢谢!

[解决办法]
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
ifstream out( "t.txt ");
string line;
int i = 0;
while(!out.eof()))
{
out > > line ;
cout < < line < < " ";
}
return 0;
}
这样写看看。。。

读书人网 >UNIXLINUX

热点推荐