Error lvalue required as left operand of assignment c++(错误左值需要作为赋值c ++的左操作数)
问题描述
整个程序基本上只允许用户移动光标,如果用户在给定的坐标范围 (2,2) 内,则允许用户键入输入.我刚刚提供了一些我认为足以解决问题的代码.
The whole program basically just allows the user to move the cursor and if the user is in the given range of coordinates (2,2), the user is allowed to type the input. I have just provided some bits of the code which I thought would be enough for solving the problem.
我不知道是什么导致了这个问题.你能解释一下为什么会这样吗?
I don't know what is causing this problem.Can you also explain why is it happening !!
void goToXY(int ,int);
用两个整数创建了一个函数.
Created a function with two ints.
int X = 0, Y = 0;
初始化两个整数.
if(X = 2 && Y = 2){
cin >> input;
}
这是错误所在(在上面)
This is where the error is(it's above)
void goToXY(int x = 0, int y = 0) {
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
这里是我定义函数的地方(在上面)
Here's where I define the function(it's above)
推荐答案
问题出在这个if语句
if(X = 2 && Y = 2){
cin >> input;
}
条件被解释为
if(X = ( 2 && Y ) = 2){
cin >> input;
}
我想你是说
if(X == 2 && Y == 2){
cin >> input;
}
考虑到最好在函数声明而不是函数定义中包含默认参数,因为通常它是在编译单元中可见的声明.
Take into account that it is better to include default arguments in the function declaration instead of the function definition because usually it is the declaration that is visible in a compilation unit.
例如
void goToXY( int = 0, int = 0 );
您也可以在提供另一个默认参数的块作用域中重新声明函数.
Also you may redeclare the function in a block scope supplying another default arguments.
这篇关于错误左值需要作为赋值c ++的左操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误左值需要作为赋值c ++的左操作数
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
