您的位置:程序门 -> linux/unix社区 -> 程序开发区



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


g++的问题,还是?不懂。。。[已结贴,结贴人:heixia108]
发表于:2007-06-11 00:14:20 楼主
#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++都运行正确,为什么?
这问题可以怎么解决呢?

谢谢!
发表于:2007-06-11 00:14:521楼 得分:0
我用的是g++
发表于:2007-06-11 08:45:462楼 得分:20
#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;
}
这样写看看。。。
发表于:2007-06-13 01:32:273楼 得分:0
我试了,上面那样不行,不过在dev_c++等上能运行能成功
改了下,下面的能行:
      while(out   > >   line   )
        {
                cout   < <   line   < <   "       ";

        }

在 "out   > >   line; "前加一行:

line   =   " ";
发表于:2007-06-13 01:32:434楼 得分:0
谢了


快速检索

最新资讯
热门点击