错误LNK2019 - 我觉得我的代码应该编译,但我收到此错误

时间:2013-04-23 02:18:19

标签: c++ lnk2019

如果有人能帮我弄清楚为什么会发生这种错误,我会非常高兴。我觉得我的代码应该编译但是我的两个void函数都出现了这个错误。

这是我的代码......

#include<iostream>
#include<iomanip>
#include<fstream>


using namespace std;

// global constant variables
const int YEARS = 8;
const int MONTHS = 12;
const int SPACER =5;

// function prototypes

// function to read in values
void getData(double[][MONTHS], int[]);
// function to display values in table format
void printData(double[][MONTHS], int[]);


// function to print data to screen in table format using arrays

int main()
{
    double rain [YEARS][MONTHS];
    int years[YEARS];

    getData(rain, years);
    printData(rain, years);

return 0;
}


// function definitions 

void getData (double rainArray[][YEARS], int yearArray[])
{
    ifstream fin;

    fin.open("rainfall.txt");

    if (!fin)
    {
        cout << "Error opening file, shutting down now.\n" ;
        exit(EXIT_FAILURE);
    }
    else
    {
        for( int i = 0; i < YEARS; i++)
        {
            fin >> yearArray[i];
            for (int j = 0; j < MONTHS; j++)
            {
                fin >> rainArray[i][j];
            }
        }
    }
    fin.close();
}   

void printData (double rainArray[][YEARS], int yearArray[])
{

    for ( int i = 0; i < YEARS; i++){
        cout << yearArray[i] << setw(SPACER);
        for ( int j = 0; j < MONTHS; j ++)
            cout << rainArray[i][j] << setw(SPACER);
    }
    cout << endl;
}

1 个答案:

答案 0 :(得分:1)

您的genData参数和rain数组中的维度不匹配: 你有:

  double rain [YEARS][MONTHS];

但以错误的方式使用它:

 void getData (double rainArray[][YEARS], int yearArray[])
                    //^^^ should be rainArray[YEARS][MONTHS]

printData函数的类似问题