- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到这个错误
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'void')
这是我的 main.cpp
#include <iostream>
#include "WEATHERFORECASTER.h"
using namespace std;
int main()
{
WeatherForecaster yearData;
cout<<yearData.printDaysInData()<<endl;
}
这是我的头文件
#ifndef WEATHERFORECASTER_H
#define WEATHERFORECASTER_H
#include <iostream>
struct ForecastDay{
std::string day;
std::string forecastDay;
int highTemp;
int lowTemp;
int humidity;
int avgWind;
std::string avgWindDir;
int maxWind;
std::string maxWindDir;
double precip;
};
class WeatherForecaster
{
public:
WeatherForecaster();
~WeatherForecaster();
void addDayToData(ForecastDay);
void printDaysInData(); //prints the unique dates in the data
void printForecastForDay(std::string);
void printFourDayForecast(std::string);
double calculateTotalPrecipitation();
void printLastDayItRained();
void printLastDayAboveTemperature(int); //argument is the temperature
void printTemperatureForecastDifference(std::string);
void printPredictedVsActualRainfall(int); //argument is days out, such as 1 = 1 day out, 2 = 2 days out, 3 = 3 days out
std::string getFirstDayInData();
std::string getLastDayInData();
protected:
private:
int arrayLength = 984;
int index;
ForecastDay yearData[984]; //data for each day
};
#endif // WEATHERFORECASTER_H
这是我的类(class)文件
#include "WEATHERFORECASTER.h"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
WeatherForecaster::WeatherForecaster()
{
//ctor
ifstream Fore; //Open up the file DATABOULDER.csv for weather data
Fore.open("DATABOULDER.csv");
if (Fore.fail()) //If it fails nothing will happen
{
}
else
{ //Otherwise open the file and begin sorting the data
string weather; //Create a string called weather
int lineIndex = 0; //Create a counter for the lines
while (getline(Fore, weather, '\n')) //Move through each line of the data by stopping at a character return
{ //Set the weather variable to that whole line of data
stringstream ss; //Create a stream using the weather string
ss << weather;
int weatherIndex = 0; //Create a new Index counter for each piece of data within the line
while (getline(ss, weather, ',')) //Go through the line and every comma store that as a weatherIndex
{
if (weatherIndex == 0) //Begin setting the pieces of the array beginning with the first index
{
string day = yearData[lineIndex].day; //If the index is 0 then set it as the .day extension
yearData[lineIndex].day = weather; //Set this equal to the weather variable in order to get the actual piece of data
}
else if (weatherIndex == 1) //If Index is 1 then this is the forecast day so use that extension
{
string forecastDay = yearData[lineIndex].forecastDay;
yearData[lineIndex].forecastDay = weather; //Set that equal to the weather variable to get actual data
}
else if (weatherIndex == 2) //If the Index is 2 then this is the high temp
{
istringstream convert(weather); //First convert weather so it can take ints
int highTemp = 0; //Create a highTemp int variable
string strHighTemp = ""; //Create a string to use with the string for converting the highTemp
strHighTemp = weather.substr(2, 2); //This allows for the H: to be removed and only a number or int
if (!(istringstream(strHighTemp) >> highTemp)) highTemp = 0;//Converting string highTemp to int highTemp and if it fails set highTemp to 0
yearData[lineIndex].highTemp = highTemp;
}
else if (weatherIndex == 3)
{
istringstream convert(weather); //Perform the exact same steps as previous for low temperatures
int lowTemp = 0;
string strLowTemp = "";
strLowTemp = weather.substr(2, 2);
if (!(istringstream(strLowTemp) >> lowTemp)) lowTemp = 0;
yearData[lineIndex].lowTemp = lowTemp;
}
else if (weatherIndex == 4) //If Index is 4 then that is humidity and we need to convert
{
istringstream convert(weather); //Convert weather to take ints
int humidity = 0; //Initialize a variable for humidity
if (!(istringstream(weather) >> humidity)) humidity = 0;//Convert string humidity to int humidity and if it fails set humidity to 0
yearData[lineIndex].humidity = humidity; //Set this index of the array to humidity variable type int
}
else if (weatherIndex == 5) //If Index is 5 then that is avgWind and we must convert
{
istringstream convert(weather); //Convert weather to take ints
int avgWind = 0; //Initialize variable for avgWind
if (!(istringstream(weather) >> avgWind)) avgWind = 0; //Convert string avgWind to int avgWind and if it fails set avgWind to 0
yearData[lineIndex].avgWind = avgWind; //Set this index of the array to the avgWind variable type int
}
else if (weatherIndex == 6) //If Index is 6 then it is the avg Wind Direction
{
yearData[lineIndex].avgWindDir = weather; //Set this index of the array to weather since it is a string
}
else if (weatherIndex == 7) //If Index is 7 then it is max Wind
{
istringstream convert(weather); //Convert weather to take ints
int maxWind = 0; //Initialize variable for maxWind
if (!(istringstream(weather) >> maxWind)) maxWind = 0;//Convert string maxWind to int maxWind and if it fails set maxWind to 0
yearData[lineIndex].maxWind = maxWind; //Set this index of the array to the maxWind variable type int
}
else if (weatherIndex == 8) //If Index is 8 then it is max Wind Direction
{
yearData[lineIndex].maxWindDir = weather; //Set equal to weather since it is a string
}
else if (weatherIndex == 9) //If Index is 9 then it is precipitation
{
istringstream convert(weather); //Convert weather to take doubles
double precip = 0; //Initialize variable for precipitation type double
if (!(istringstream(weather) >> precip)) precip = 0;//Convert string precip to int precip and if it fails set it to 0
yearData[lineIndex].precip = precip; //Set this index of the array to the precip variable of type double
}
weatherIndex++; //Increment each weatherIndex to get all lines
}
lineIndex++; //Increment each lineIndex to get all pieces from the lines
}
}
}
WeatherForecaster::~WeatherForecaster()
{
//dtor
}
void WeatherForecaster::printDaysInData()
{
//!display contents of array
for(int i = 0; i < arrayLength; i++)
{
cout<<yearData[i]<<endl;
}
}
我做了一些研究,发现了几个类似的问题,但它们对我来说毫无意义,或者与我遇到的问题不相符。它们包括:
error: no match for operator ==
C++ Error: 'no match for operator<...'
error: no match for ‘operator<<’ in ‘std::operator<<
现在我正在使用头文件中显示的结构,但我正在从充满数据的文件中填充数组。我只是对这个错误在所有这些中意味着什么感到困惑,因为我的大部分代码都适用于所有其他部分。是我头文件的问题还是怎么回事?
如有任何帮助或指导,我们将不胜感激!!!
最佳答案
您正在显示您的void
函数中已有的值:
void WeatherForecaster::printDaysInData()
{
//display contents of array
for(int i = 0; i < arrayLength; i++)
{
cout << yearData[i] << endl;
}
}
因此,在 main()
中,您只需调用它,该函数就会执行其功能:
int main()
{
WeatherForecaster yearData;
yearData.printDaysInData();
return 0;
}
您收到该错误是因为它是一个 void 函数。
关于C++ 错误 : no match for 'operator<<' (operand types are,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39984346/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎离题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a minim
家庭作业 必须同时重载 operator>(istream &in, Complex &value); public: // constructor Compl
这个问题在这里已经有了答案: What are the basic rules and idioms for operator overloading? (8 个答案) 关闭 5 年前。 有什么区别
这是文档中一个不清楚的示例,使用此运算符:http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Json-Decode#at 最佳答案 请注
我不明白这种行为: > sort([1,2,3,4]) ~~ sort([1,2,3,4]) False 你能给我解释一下吗? 为什么这两个列表(显然是相等的)根据 Perl 6 不相等。 更新 有趣
我正在尝试将 Ø 设为逻辑否定运算符。 ¬ True; multi sub prefix: ($n) { return not $n; } 当我运行上面的程序时,它返回以下错误: $
class Port { private: char * brand; char style[20]; // i.e., tawny, ruby, vintage int bo
早上好。我有一些问题。我有这些字段: name: "Mike", city: "NY", address: "something", pets: ["dog", "cat"] 我创建了索引 db.pe
我有以下代码使用 Javascript Webcrypto-API 解密 AES 加密数据,但它会导致“OperationError”并显示消息“操作因操作特定原因而失败”: function loa
我制作了一个自定义 Airflow 操作符,这个操作符接受一个输入,这个操作符的输出在 XCOM 上。 我想要实现的是使用一些定义的输入调用运算符,将输出解析为可在分支运算符内部调用的 Python,
int a = 1; a += ++a; cout << a << endl; // 4 int a = 1; a += a++; cout << a << endl; // 3 为什么这两个例子有不
我有这个队列的实现: #include using namespace std; template struct elem_q { T inf; elem_q* link; }; template
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我对 C++ 中的运算符重载有疑问。我有代表复数的结构,我正在重载运算符,所以我可以用复数进行计算。Visual Studio 2012 给我这个错误:1 IntelliSense:没有运算符“!=”
我正在尝试创建一个 BoolArray 类,它表示一个 bool 值数组,而不是为每个 bool 变量保存 1 个 bool 值。它使用 1 个字符变量来表示使用位的 8 个 bool 值,并节省内存
我类有 2 个运算符有点问题。 我的类(class)宣布: template class MyMap{ keyType keys[MAX]; valueType values[MAX
我有类的迭代器模板和用于 for 语句的类。 template class Itr2 { public: Itr2() { } ~Itr2() { } typedef t
Section 7.2 Enumeration declarations 没有说明任何关于 operator!=() 和作用域的 operator==()枚举。但是下面的代码可以编译。 #includ
我需要将一个 int 序列化到本地文件并将其读入内存。这是代码 #include "stdafx.h" #include #include using namespace std; int _tm
operator += 这样定义对吗?! void operator +=(const BigNumber& other) { *this=(*this) + other; } 在这样的类中:
我是一名优秀的程序员,十分优秀!