With the code below I'm trying to rub out the { } ,
symbols and blanck spaces in the file dummyValues.dat but the result is the first 3 numbers and a bunch of zeros that I don't understand how they are appearing. Actually the programme does never stop.
码:
#include<iostream>
#include<cmath>
#include<string>
#include"complejos.h"//'using namespace std;' command is in here
#include<fstream>
#include<iomanip>
#include<cstdio>
int main() {
double dato;
char aux;
ifstream benchmarks;
benchmarks.open("dummyValues.dat");
if (benchmarks.is_open()) {//first if
benchmarks.get(aux);
while (aux != 'X') {
if (aux == '{' || aux == '}' || aux == ',' || aux == ' ') {
benchmarks.get(aux);
} else {
benchmarks.unget();
benchmarks>>dato;
cout<<dato;
benchmarks.get(aux);
};
};//end of while
} else {
cout<<"ERROR: couldnt open the file"<<endl;
};//end of first if
benchmarks.close();
return 0;
}; //end of main
执行结果:
5.120.10.25000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
而原始文件是
{5.12, 0.1, 0.25} {{0.10, 4, 3, 2, 1, 1.44, 10.2}} {11.1, 12.2, 13.3, 14.4, 15.5, 16.6} 1000 2000 {{{{ 5.12, 0.1} {17.7, 18.08, 19.0, 020.0} {1.115, 2.0, 3.01, 4.65, 5, 6, 7, 8, 9, 10.0}, 3000 4000 { 5.12, 0.1} {117.7, 118.08, 119.0, 0120.0} {11.115, 21.0, 31.01, 41.65, 51, 61, 71, 81, 91, 110.0} 5000 6000 X
任何提示错误发生在哪里?