Simple C++ input from file…how to?

后端 未结 4 1294
执笔经年
执笔经年 2021-02-03 16:35

I have a file:

P 0.5 0.6 0.3
30 300
80 150
160 400
200 150
250 300
T
r  45 0 0
s 0.5 1.5 0 0
t 200 –150
.
.
.

When I read in \'P\' I know that

4条回答
  •  花落未央
    2021-02-03 17:13

    user to read text file line by line and then run string word;

    ifstream fin(your file)
    while(! fin.eof())
    {
        string line = fin.getline();
        istringstream iss(line, istringstream::in);
        string token;
        while( iss >> token)     
        {
          if (token.compare("T")) {
            ...
          } else {
            float f = atof(token.c_str());
         }
        }
    }
    

提交回复
热议问题