Очистка файла данных для чтения только чисел в C ++ - PullRequest
0 голосов
/ 08 мая 2020

Мне нужно прочитать с помощью C ++ файл с расширением .wdx (предоставляется Mathematica). Мне удалось получить файл как .dat и .txt, получив что-то вроде этого минимального примера (dummyValues.dat):

{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} X

Как видите, это беспорядок с пробелами и {, } символы. Меня интересует только получение файла с числами (десятичная дробь обозначается точкой, '.'). Как я могу сделать это с помощью файла .wdx или .dat?


Я пробовал это

#include<iostream>
#include<cmath>
#include<string>
#include"complejos.h"//'using namespace std;' command is in here
#include<fstream>
#include<iomanip>

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>>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

Но получаю эту ошибку:


error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   while (aux != "X") {
                 ^~~
 error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (aux == "{" || aux == "}" || aux == "," || aux == " ") {
                ^~~
 error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (aux == "{" || aux == "}" || aux == "," || aux == " ") {
                              ^~~
 error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (aux == "{" || aux == "}" || aux == "," || aux == " ") {
                                            ^~~
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (aux == "{" || aux == "}" || aux == "," || aux == " ") {

...