从.txt文件读取时,我想要转换文件中的一些值,将string转换为doubles。通常,我可以打印所需的值:
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();终端:
Voltage 0: 5.0000000
Voltage 1: 8.0000000
Voltage 2: 1.1000000但是,当我尝试使它们成为double时,我将命令替换为
cout << "Voltage " << i << ": " << atof(line.substr(0, 9)) << endl;我得到了以下错误:
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 ***这里有什么线索吗?如果我错过了一些明显的东西,很抱歉,我对C++还很陌生
https://stackoverflow.com/questions/62917856
复制相似问题