#include <iostream>
#include <windows.h>
using namespace std;
int go_to(int x, int y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
return SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void main(){
int a=1;
while(a<10){
a++;
cout<<"work"<<endl;
go_to(3,6);
cout<<"work"<<endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这个循环只工作一次,也许你知道哪里有问题?我问题是在Cord中,但是不知道使用CORD的类似方法.
变量a仅由将a++;其值增加1 的行修改,并且不会传入go_to(x,y),因此它不会受到该函数的影响.
您的循环肯定会运行值a = {1到9},go_to(3, 6)每次调用,并且还打印两次.如果你不这么认为我相信你错了.