我在第102, 115, and 128
行上遇到错误。我究竟做错了什么?它说:
数字常量
之前的预期unqualified-id
我不知道这意味着什么。我已经尝试解决这个问题已经有一个星期了,而且这个问题将在周三的C ++课程中进行。我真的可以在这里使用一些外部建议。我做错了什么:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <conio.h>
#include <string>
using namespace std;
double qMeter = 0;
double hMeter = 0;
double oneMeter = 0;
int solDay = 0;
string garbage;
string localTime;
string decSol;
ifstream input;
ofstream output;
//function prototypes
double low(double lowTemp);
double high(double highTemp);
float average(double avgTemp);
int main()
{
input.open("curiosity234x.dat"); //opens input data file
output.open("output.dat"); //opens output data file
for (int i = 0; i < 4; i++) //gets rid of the first four lines
{
getline(input,garbage);
cout << endl;
}
while (!input.eof())
{
int count;
double newOneMeter;
double newHMeter;
double newQMeter;
if (solDay == 2) //processes data for the second solar day
{
input >> solDay >> localTime >> decSol
>> newOneMeter >> newHMeter >> newQMeter;
oneMeter = oneMeter + newOneMeter;
hMeter = hMeter + newHMeter;
qMeter = qMeter + newQMeter;
count++;
output << solDay << fixed << setprecision(1) << setw(5)
<< "Solar" << "Average" << "Low" << "High"
<< "Average" << "Low" << "High"
<< "Average" << "Low" << "High"
<< "Day" << "Temp" << "Temp" << "Temp" << "Temp" << "Temp"
<< "Temp" << "Temp" << "Temp" << "Temp"
<< fixed << setprecision(15) << "1 meter" << ".5 meters"
<< ".25 meters"
<< average(oneMeter) << low(oneMeter) << high(oneMeter)
<< average(hMeter) << low(hMeter) << high(hMeter)
<< average(qMeter) << low(qMeter) << high(qMeter);
}
if (solDay == 3) //processes data for the third solar day
{
input >> solDay >> localTime >> decSol
>> newOneMeter >> newHMeter >> newQMeter;
oneMeter = oneMeter + newOneMeter;
hMeter = hMeter + newHMeter;
qMeter = qMeter + newQMeter;
count++;
output << solDay << fixed << setprecision(1) << setw(5)
<< "Solar" << "Average" << "Low" << "High"
<< average(oneMeter) << low(oneMeter) << high(oneMeter)
<< average(hMeter) << low(hMeter) << high(hMeter)
<< average(qMeter) << low(qMeter) << high(qMeter);
}
}
cout << endl << "The output.dat file has been written and transmitted.";
/*
reads first line. Assigns first string to 'int solDay'
second to 'string time', third to decSol, fourth to oneMeter,
fifth to hMeter and sixth to qmeter. Meters should have setw().
*/
getch();
return 0;
input.close();
output.close();
}
//functions used in main
double low(double lowTemp)
{
int test = 10,000;
double least;
if (lowTemp < test)
{
lowTemp = test;
lowTemp = least;
}
return least;
}
double high(double highTemp)
{
int test = 10,000;
double most;
if (highTemp < test)
{
highTemp = test;
highTemp = most;
}
return most;
}
float average(double avgTemp)
{
avgTemp = avgTemp / count;
return avgTemp;
}
答案 0 :(得分:7)
当我遇到它时,我搜索了这个错误。我的烦恼的原因?我试图给一个与#define值相同的类,该值已经从第三方API头包含在我的项目中。尝试一个不同的类名,我把它编译好了!
答案 1 :(得分:4)
第102行和第115行的错误是由于10,000
中有逗号,但它应该是10000
,逗号不能用作数字分隔符。你实际使用的是comma operator,它从从左到右评估它的表达式,只返回最后一个。所以在这种情况下:
int test = 10,000;
^ ^
| Expression 2
Expression 1
因为=
具有更高的优先级,所以它首先出现,而另一方面又留下语法错误:
int test = (10,000);
会导致值10
被丢弃,八进制文字 000
被分配给test
。
第128行的最后一个错误是因为main
计数是本地的,但你试图在average
中使用它,你需要通过count
作为第二个参数中。