Reputation: 1200
So I am working on this project where I have to read in a CSV file which contains numbers that are represented in scientific notation. So far what I have is to read in each number then convert that number into string then convert it to double with stringstream but I am not sure if this is the correct way to do it. Any advice / suggestion would be helpful!
double temp;
istringstream in(line); //line is the string which contains the number, ex: 3.30144800e+03
in >> temp;
arr[w++] = temp;
Upvotes: 1
Views: 4711
Reputation: 20093
You can convert a string to a double with std::atof
istringstream in(line);
double value(atof(in.str().c_str()));
OR you can simply stream the double out of the buffer...
double value;
in >> value;
Upvotes: 1