Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C++; C++初学者,正如标题所说,我试图读取一行逐行循环的文件,同时在行进到下一行之前对行的数据进行计算。 int main() { ifstream in_file; string name; int kiloWatt{}; int amperage{}; int cores{3}; int voltage{480}; double powerFactor{0.8}; double efficiency{0.93}; double root{}; in_file.open("../test.txt"); if(!in_file){ cerr <<"Problem opening file" << endl; return 1; } while (in_file >> name >> kiloWatt){ root = sqrt(cores); amperage = (kiloWatt*1000)/(root*voltage*powerFactor*efficiency); cout << setw(10) << name << setw(10) << kiloWatt << setw(10) << amperage << setw(10) << root << endl; } in_file.close(); return 0;_C++_Parsing_Iostream_Iomanip - Fatal编程技术网

在C++; C++初学者,正如标题所说,我试图读取一行逐行循环的文件,同时在行进到下一行之前对行的数据进行计算。 int main() { ifstream in_file; string name; int kiloWatt{}; int amperage{}; int cores{3}; int voltage{480}; double powerFactor{0.8}; double efficiency{0.93}; double root{}; in_file.open("../test.txt"); if(!in_file){ cerr <<"Problem opening file" << endl; return 1; } while (in_file >> name >> kiloWatt){ root = sqrt(cores); amperage = (kiloWatt*1000)/(root*voltage*powerFactor*efficiency); cout << setw(10) << name << setw(10) << kiloWatt << setw(10) << amperage << setw(10) << root << endl; } in_file.close(); return 0;

在C++; C++初学者,正如标题所说,我试图读取一行逐行循环的文件,同时在行进到下一行之前对行的数据进行计算。 int main() { ifstream in_file; string name; int kiloWatt{}; int amperage{}; int cores{3}; int voltage{480}; double powerFactor{0.8}; double efficiency{0.93}; double root{}; in_file.open("../test.txt"); if(!in_file){ cerr <<"Problem opening file" << endl; return 1; } while (in_file >> name >> kiloWatt){ root = sqrt(cores); amperage = (kiloWatt*1000)/(root*voltage*powerFactor*efficiency); cout << setw(10) << name << setw(10) << kiloWatt << setw(10) << amperage << setw(10) << root << endl; } in_file.close(); return 0;,c++,parsing,iostream,iomanip,C++,Parsing,Iostream,Iomanip,kwat是一个整数,因此在第一行,它将读取23,看到一个非整数字符并停止。下一个名称将是“.5”,您将尝试将“name2”读入千瓦,这将失败,因为它不是一个数字——打破您的循环 将千瓦更改为双精度以解决此问题。千瓦是一个整数,因此在第一行,它将读取23,看到一个非整数字符并停止。下一个名称将是“.5”,您将尝试将“name2”读入千瓦,这将失败,因为它不是一个数字——打破您的循环 将千瓦更改为双倍以解决此问题。千瓦应该是双倍的。现在我觉得很傻。我已经看了好几个小时了。干杯,伙计千瓦应该是双倍。现

kwat
是一个整数,因此在第一行,它将读取
23
,看到一个非整数字符并停止。下一个
名称
将是
“.5”
,您将尝试将
“name2”
读入
千瓦
,这将失败,因为它不是一个数字——打破您的循环


千瓦
更改为双精度以解决此问题。

千瓦
是一个整数,因此在第一行,它将读取
23
,看到一个非整数字符并停止。下一个
名称
将是
“.5”
,您将尝试将
“name2”
读入
千瓦
,这将失败,因为它不是一个数字——打破您的循环


千瓦
更改为双倍以解决此问题。

千瓦
应该是双倍的。现在我觉得很傻。我已经看了好几个小时了。干杯,伙计<电码>千瓦应该是双倍。现在我觉得自己很傻。我已经看了好几个小时了。干杯,伙计!
name1 23.5
name2 45.6
name3 234.8