【发布时间】:2020-11-05 03:04:33
【问题描述】:
从.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++ 还是很陌生
【问题讨论】:
标签: c++ string double root atof