奇怪的编译错误

Strange compilation errors

本文关键字:错误 编译      更新时间:2023-10-16

有人能告诉我编译时错误的含义并帮助我解决吗?

这里有一个错误:

C: \doc1\collect2.exe[Error]ld返回1退出状态

这是文本文件:

 T(F)       R1        R2       R3        R4
 95.0     95.20     66.10     43.10     29.00
 96.0     96.10     67.60     43.50     31.20
 97.0     97.40     67.00     43.70     30.50
 98.0     97.20     69.10     44.10     30.70
 99.0     98.90     68.00     44.70     32.80
100.0    99.50     71.10     45.10     31.50
101.0   101.00     71.20     45.30     31.60
102.0   101.60     71.00     45.70     30.50
103.0   101.80     73.10     46.30     32.50
104.0   103.70     73.50     46.60     32.70
105.0   105.60     72.80     47.10     33.60

这是我的源

#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
using namespace std;
void read ();
void slope(double,double,double,double,double,int,double);
void write(double,double,double,double,double,double);
double temp, R1, R2, R3, R4,rsq;
int main ()
{
    read();
    return 0;   
}
void read()
{
    ifstream indata("c:\doc1\temperaturedata.txt");
    int indx=0;
    if(indata == NULL)
    {
        cout<< "There is no file go get it from the CD"<< endl;
        return;
    }
    const int columns = 5;
    const int rows = 11;
    double Ihatearray[rows][columns];
    string temparature;
    getline(indata, temparature);
    for(int i = 0; i < rows; ++i)
    {
        for (int j = 0; j < columns; ++j)
            {
                cout << "t" << flush;
                indata >> Ihatearray[i][j];
                cout.setf(ios::fixed);
                cout << setprecision(2) << Ihatearray[i][j] <<flush;
            }
            cout << endl;
            double temp[20], R1[20],R2[20],R3[20],R4[20];
    }
    //indata.close();
    slope(temp, R1, R2, R3, R4,indx,rsq);
}
void slope(double x[5], double y[], double& m, double& b, int n,double& r)
{
    int i;
double xsum = 0., ysum = 0., xave, yave, x2sum = 0., y2sum = 0.,xysum =0.;
for(int i = 0; i < n; i++)
{
    xsum  += x[i];
    ysum  += y[i];
    x2sum += x[i] * x[i];
    y2sum += y[i] * y[i];
    xysum += x[i] * y[i];
}
xave=xsum/n;
yave=ysum/n;
m=(xysum-yave*xsum)/(x2sum-xave*xsum);
b=yave-m*xave;
r=(xysum-n*xave*yave)/(sqrt(x2sum-n*xave*xave)*sqrt(y2sum-n*yave*yave));
write (temp, R1, R2, R3, R4,rsq);
}
void write (double temp [], double R1[], double R2[], double R3[],double R4[],double
            rsq)
{
    //Where I will print out a table of the results.
}
void slope(double,double,double,double,double,int,double);
void write(double,double,double,double,double,double);

void slope(double x[5], double y[], double& m, double& b, int n,double& r)
void write (double temp [], double R1[], double R2[], double R3[],double R4[],double rsq)

发现差异吗?这些声明和定义必须匹配。

更多错误,你的代码看起来像这个

double temp, R1, R2, R3, R4,rsq;
void read()
{
    ...
    for(int i = 0; i < rows; ++i)
    {
        ...
        double temp[20], R1[20],R2[20],R3[20],R4[20];
    }
    //indata.close();
    slope(temp, R1, R2, R3, R4,indx,rsq);
}

现在看看您所写的内容,您已经声明了tempR1R2等两次。现在,当您调用slope时,您认为哪个声明适用?以下是规则,{}中的声明仅在{}中可见。

我觉得你的编码应该更有条理。这些只是细节,但细节必须正确。