我有这个代码可以与 ncurses 一起使用:
#include <iostream>
#include <string>
#include <fstream>
#include <ncurses.h>
#include <cstdlib>
//char a='a';
int c=0;
bool ex = false;
void mva()
{
std::cout << "Nothing here yet, move along." << std::endl;
}
void cho()
{
std::cout << "Choose a valid option noob!" << std::endl;
}
void menu()
{
std::cout << "Welcome." << std::endl;
std::cout << "Choose an option" << std::endl;
std::cout << "1." << std::endl;
std::cout << "2." << std::endl;
std::cout << "3." << std::endl;
std::cout << "4. About" << std::endl;
std::cout << "5. exit" << std::endl;
}
void pause()
{
std::cin.get();
std::cin.ignore();
}
int main()
{
initscr();
//clear();
refresh();
//system("clear");
while (ex != true)
{
menu();
std::cin >> c;
switch (c)
{
case 1:
mva();
pause();
system("clear"); //unfortunately, there is no clean variant to this :(
break;
case 2:
mva();
pause();
break;
case 3:
mva();
pause();
break;
case 4:
std::cout << "About" << std::endl;
std::cout << "Programmed by nnmjywg." << std::endl;
pause();
break;
case 5:
std::cout << "Press enter to exit" << std::endl;
pause();
ex = true;
break;
default:
cho();
pause();
break;
}
}
endwin();
return 0;
}
It should work normally, but I'm absolutely baffled when I see this strange line formatting. In addition to that, I also can't see what I enter (with std::cin
)
当你的程序调用initscr
,ncurses(实际上anycurses 的实现)初始化终端模式以允许自行打印回车符和换行符(“换行符”)。打印换行符不会产生回车符。
但是 iostream 的endl
只是换行。当您打印到cout
这样,你就会看到楼梯。
当使用诅咒时,cout
and cin
并不是真正有用。使用getch
(or wgetch
) 读取输入。另外,使用诅咒echo
(or noecho
)来控制是否回显您提供的输入getch
。诅咒echo
没有影响cin
(终端同样已设置为不回显输入,并且curses知道何时回显)。
进一步阅读:
- Getch() 与 Linux C++ 中的显示函数不兼容
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)