首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++文件读写有关问题

2012-02-19 
C++文件读写问题代码如下:#include iostream#include fstream#include vector#include iomanipusi

C++文件读写问题
代码如下:
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
using   namespace   std;

int   main()
{
                ifstream   fin( "1 ");
                vector <   pair   <double,   double>   >   t_s;
                pair <double,double>   tmp;

                while(!fin.eof())
                {
                                fin> > tmp.first> > tmp.second;
                                t_s.push_back(tmp);
                }
                fin.close();

                ofstream   fout( "t_s ");
                vector <   pair   <double,   double>   > ::iterator   iter;
                for(iter=t_s.begin();   iter!=t_s.end();   ++iter)
                                fout < <setiosflags(ios::left) < <iter-> first < < '\t ' < <iter-> second < <endl;
                fout.close();
}
测试用文件1的内容是:
1.111   2.222
2.222   3.333
输出文件的内容是:
1.111   2.222
2.222   3.333
2.222   3.333
多了一行数据,哪出了问题?

[解决办法]
while(fin> > tmp.first> > tmp.second)
{
t_s.push_back(tmp);
}

热点排行