【发布时间】:2025-12-25 01:05:13
【问题描述】:
正在阅读的文本文件
1 1 1
1.2 -2.3 0.4
-2 -3 -4
+0 -2 8.85
2.345
我的代码:
#include <iostream>
#include <fstream>
using namespace std;
double readFile(ifstream &myfile, double &a, double &b, double &c);
int main()
{
int counter = 0;
double a, b, c;
string line, inputFile, outputFile;
cout << "Enter the name of your input file: ";
cin >> inputFile;
cout << "Enter the name of your output file: ";
cin >> outputFile;
ifstream myfile(inputFile);
if(myfile.is_open())
{
while(!myfile.eof())
{
readFile(myfile, a, b, c, counter);
calculations(a, b, c);
}
}
else cout << "unable to open file";
return 0;
}
double readFile(ifstream &myfile, double &a, double &b, double &c)
{
//Reads one line of the file
myfile >> a >> b >> c;
cout << a << " " << b << " " << c << endl;
}
我想要做的是,如果最后一行没有 3 个值,我希望有某种停止代码,如果它的值少于 3 个,它将停止处理,并且前一行的剩余值不会是分配
【问题讨论】:
-
然后,打开警告,你应该得到一个
readFile()方法没有返回任何东西。
标签: c++