错误左值需要作为赋值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.
相关文章