+ -
当前位置:首页 → 问答吧 → 一个文本输入的问题。。 float

一个文本输入的问题。。 float

时间:2011-12-27

来源:互联网

a b 22.2  
; A7 y) L, c7 m8 Y" @a b 33.2  
8 J' g1 P0 q# b: {5 B: \* [a b 33.2
; S' F# V* f3 f8 e2 u5 ga b 22.3
  u5 I; l4 A* l' N4 w( L这是文本内容
复制内容到剪贴板
代码:

#include <iostream>
#include <list>
#include <fstream>
#include <string>
#include<map>
using namespace std;
int main()
{
    ifstream read("123.txt");
    float word;
    list<float>mylist;
   
  while(read)
{  
   read>>word;

   mylist.push_back(word);

}


   
list<float>::iterator iter;
for ( iter=mylist.begin() ; iter != mylist.end(); iter++ )
    cout << *iter<< endl;
   
system("pause");


}
这是代码。。 $ ?) T0 l' Z  e+ l& u
这个代码碰到非float型的内容后就会停止输入内容到list里面,  这个怎么解??

作者: alleni   发布时间: 2011-12-27

复制内容到剪贴板
代码:
#include <string>
#include<map>
using namespace std;
int main()
{
        ifstream read("123.txt");
        float word;
        list<float>mylist;
        read.seekg(4,fstream::cur);
        read>>word;
        mylist.push_back(word);
        while(1)
        {  
                read.seekg(5,fstream::cur);
                read>>word;
                if(!read)break;
                mylist.push_back(word);
        }

        list<float>::iterator iter;
        for ( iter=mylist.begin() ; iter != mylist.end(); iter++ )
                cout << *iter<< endl;

        system("pause");


}

作者: 月夜幻影   发布时间: 2011-12-27