Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.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++ 二进制'<<';:未找到接受类型为';的右操作数的运算符;温度统计数据';(或没有可接受的转换),第36行_C++ - Fatal编程技术网

C++ 二进制'<<';:未找到接受类型为';的右操作数的运算符;温度统计数据';(或没有可接受的转换),第36行

C++ 二进制'<<';:未找到接受类型为';的右操作数的运算符;温度统计数据';(或没有可接受的转换),第36行,c++,C++,这段代码有两个错误,这两个错误是: 没有运算符“您试图打印的结果是一个结构,而C++不知道如何自动执行复杂的用户定义值 您期望得到什么“但是,它试图输出函数的结果,因此我不知道问题的真正原因。”--为什么您不知道?您不知道函数的结果是“temperature\u stats”类型,与编译器消息完全匹配吗? #include <fstream> #include <iostream> using namespace std; struct temperature_sta

这段代码有两个错误,这两个错误是:


没有运算符“您试图打印的结果是一个结构,而C++不知道如何自动执行复杂的用户定义值

您期望得到什么
“但是,它试图输出函数的结果,因此我不知道问题的真正原因。”--为什么您不知道?您不知道函数的结果是“temperature\u stats”类型,与编译器消息完全匹配吗?
#include <fstream>
#include <iostream>

using namespace std;

struct temperature_stats {
    string month;
    int hi_temp = 0;
    int low_temp = 0;
};

temperature_stats months_per_year[12];

void loadData(ifstream& inFile, temperature_stats[], int& size);
temperature_stats averageHigh(temperature_stats array[], int size);
temperature_stats averageLow(temperature_stats array[], int size);

temperature_stats averageHigh(temperature_stats array[], int month) {
    // this function calculates and returns the high temperature and the corresponding month of the year
    return array[month];
}

temperature_stats averageLow(temperature_stats array[], int month) {
    // this function calculates and returns the low temperature and the corresponding month of the year
    return array[month];
}

int main() {
    ifstream inFile;

    int rows = 12;

    loadData(inFile, months_per_year, rows);

    for (int j = 0; j < 12; j++) {
        cout << "The highest temperature recorded in the month of " << months_per_year[j].month << " was "
            << averageHigh(months_per_year, j) << endl;
    }

    inFile.close();

}

void loadData(ifstream& inFile, temperature_stats[], int& size) {
// this function reads and sorts data from a text file
    inFile.open(); // file location, can be interchangable if needed

    if (!inFile) {
        cout << "404 ERROR: FILE NOT FOUND\n" << endl; // debug line
    }

    if (inFile) {
        cout << "FILE FOUND!\n" << endl; // debug line
    }

    for (int i = 0; i < 12; i++) {
        inFile >> months_per_year[i].month >> months_per_year[i].hi_temp >> months_per_year[i].low_temp;
        cout << months_per_year[i].month << " " << months_per_year[i].hi_temp << " " 
            << months_per_year[i].low_temp << endl; // debug line
    }
}
std::ostream& operator<<(std::ostream& os, const temperature_stats& ts) {
    os << "Temperature: "
      << ts.month
      << " low: " << ts.low_temp
      << " high: " << ts.hi_temp;
    return os;
}