Reading from a .txt
file, I would like to convert some values from a file, converting a string
into double
s. Normally, I can print the desired values:
string line;
ifstream f;
f.open("set11.txt");
if(f.is_open()) {
for(int i = 0; i < 3; i++) {
getline(f, line);
cout << "Voltage " << i << ": " << line.substr(0, 9) << endl;
}
}
f.close();
Terminal:
Voltage 0: 5.0000000
Voltage 1: 8.0000000
Voltage 2: 1.1000000
However, when I try to make them double
, I replace the command with
cout << "Voltage " << i << ": " << atof(line.substr(0, 9)) << endl;
and I get the following error:
Voltage 0: Error: atof parameter mismatch param[0] C u C:\Users\User\Desktop\Physics\FTE\Root\set11.c(26)
(class G__CINT_ENDL)9129504
*** Interpreter error recovered ***
Any clues here? Sorry if I'm missing something obvious, I'm quite new to C++