在c++中没有匹配的 "operator<<"。

问题描述 投票:0回答:1

当我运行这段代码时,我得到以下错误信息截图 erore

50:7: error: no match for 'operator<<' (operand types are 'std::__ndk1::ostream' {aka 'std::__ndk1::basic_ostream'} and 'void') cout << generateRandomNumber();compilation terminated due to -Wfatal-errors.

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
// class game
class mathGames 
{
public:
mathGames();
void generateRandomNumber();
void calculate();
void show();
void answer();
private:
int x;
int y;
int z;
char ans;
};
// constructor 
mathGames::mathGames()
{
x = 0;
y = 0;
}
// generate random numbers 
void  mathGames::generateRandomNumber()
{
srand (time(NULL));
x = rand()%9+1;
y = rand()%9+1;
}
// calculate numbers 
void mathGames::calculate()
{
z = x + y;
}
// show generate number 
void mathGames::show()
{
cout << " " << x << " + " 
<< y << " = " << z << endl;
}
// user answer 
void mathGames::answer()
{
cout << " true or false (t/f) ? ";
cin >> ans;
if (ans == 't') 
cout << 
generateRandomNumber();
}
// main
int main ()
{
mathGames number;
number.generateRandomNumber();
number.calculate();
number.show();
number.answer();
}
c++ c++11 visual-c++ c++14 c++17
1个回答
0
投票

你的函数正在返回 void. 因此,你不能打印任何东西。

© www.soinside.com 2019 - 2024. All rights reserved.