无效的用户定义转换:C++ 错误
Invalid user-defined conversion: C++ error
我正在使用 Code::Blocks 作为我的 IDE 在 C++ 中制作一个(非常)简单的计算器程序。我在我的程序中遇到了一些错误。请看看我的代码并告诉我错误是什么。谢谢。
#include <iostream>
#include <limits>
#include <conio.h>
int num1;
char Operator;
int num2;
void sum() {
std::cin >> num1; // User inputs first number
std::cin >> Operator; // User inputs operator
std::cin >> num2; // User inputs second number
// These if statements identify the operator and perform the appropriate
// operation
if ( Operator == '+' ) {
std::cout << num1 + num2;
}
else if ( Operator == '-' ) {
std::cout << num1 - num2;
}
else if ( Operator == '*' ) {
std::cout << num1 * num2;
}
else if ( Operator == '/' ) {
std::cout << num1 / num2;
}
else {
std:: cout << "Incorrect value/s entered.";
}
}
int main {
std::cout << "Press q to quit the program.";
while(1) {
sum()
if(ascii_value==113) { // For Q
break;
}
}
return 0;
}
错误:
error: invalid user-defined conversion from 'std:: basic_ostream<char>' to
'int' [-fpermissive]
error: expected unqualified-id before 'while'
我是四天前才开始学习C++的,所以我对错误了解不多,请大家谅解。另外,我不确定我是否需要包括限制,所以请在下面的评论中告诉我。
int main
不是函数声明 将其更改为
int main()
和 sum()
需要一个分号。
在 if(ascii_value==113)
中,ascii_value
在代码中的任何地方都没有定义
我正在使用 Code::Blocks 作为我的 IDE 在 C++ 中制作一个(非常)简单的计算器程序。我在我的程序中遇到了一些错误。请看看我的代码并告诉我错误是什么。谢谢。
#include <iostream>
#include <limits>
#include <conio.h>
int num1;
char Operator;
int num2;
void sum() {
std::cin >> num1; // User inputs first number
std::cin >> Operator; // User inputs operator
std::cin >> num2; // User inputs second number
// These if statements identify the operator and perform the appropriate
// operation
if ( Operator == '+' ) {
std::cout << num1 + num2;
}
else if ( Operator == '-' ) {
std::cout << num1 - num2;
}
else if ( Operator == '*' ) {
std::cout << num1 * num2;
}
else if ( Operator == '/' ) {
std::cout << num1 / num2;
}
else {
std:: cout << "Incorrect value/s entered.";
}
}
int main {
std::cout << "Press q to quit the program.";
while(1) {
sum()
if(ascii_value==113) { // For Q
break;
}
}
return 0;
}
错误:
error: invalid user-defined conversion from 'std:: basic_ostream<char>' to
'int' [-fpermissive]
error: expected unqualified-id before 'while'
我是四天前才开始学习C++的,所以我对错误了解不多,请大家谅解。另外,我不确定我是否需要包括限制,所以请在下面的评论中告诉我。
int main
不是函数声明 将其更改为
int main()
和 sum()
需要一个分号。
在 if(ascii_value==113)
中,ascii_value
在代码中的任何地方都没有定义