如何用c++做到光标效果?

来源:百度知道 编辑:UC知道 时间:2024/09/21 16:33:02
怎样可以用c++做到用移动光标来选择菜单
===========================================
1.choice A
2.choice B
3.choice C
===========================================
普遍的方法是用switch来做
如果要做到用光标选择的效果怎么弄?
怎样可以用c++做到用移动光标来选择菜单,像下面
===========================================
-》1.choice A
2.choice B
3.choice C
===========================================
我想知道一下大家的做法,谢谢

#include <iostream>
#include <conio.h>
using namespace std;

int pos = 0;
char* p[3] = {"A-Choice","B-Choice","C-Choice"};
bool Menu()
{
for( int i = 0;i<3; ++ i )
{
if( pos == i )
cout<<"-->";
cout<<*(p+i)<<endl;
}

return true;
}
int main()
{
while( Menu() )
{
char ch = getch();
if( ch == 'w' ) //按w可以向上
{
if( pos > 0 )
--pos;
}
else if ( ch == 's' ) //按s可以向下
{
if( pos < 2 )
++pos;
}
system("cls");
}
}

试试看哈。呵呵
退出的方法自己研究,不过是menu返回false就可以了。或者手动添加break到While中。