ncurses getch() 奇怪的输出?
ncurses getch() weird output?
我已经安装了 ncurses.h 库并开始试验我构建的 getch() function.When 和 运行 这段代码起初对我来说似乎没问题,控制台打印出来一个奇怪的字符:'�'(如果它不显示并显示为 space 这里是一个屏幕截图:https://prnt.sc/gbrp7b)控制台开始向它发送垃圾邮件,但如果我输入一个字符,它就会显示在输出中,但仍然是 '?' 垃圾邮件。这是代码:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
cout << "You entered : " << input << endl;
//break;
}
return 0;
}
所以我想尝试使用 if 语句来阻止它发送垃圾邮件,但代码无法识别该字符:
它给出了这个错误:
error: character too large for enclosing character literal type
对于此代码:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
if(input!='�'){
cout << "YOu entered : " << input << endl;
}
}
return 0;
}
我正在使用 OSX Sierra 10.12.5 并使用 eclipse Oxygen
您需要使用 initscr()
初始化 ncurses
并使用 endwin()
函数关闭它:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
initscr();
while (true) {
input = getch();
cout << "YOu entered : " << input << endl;
}
endwin();
return 0;
}
我已经安装了 ncurses.h 库并开始试验我构建的 getch() function.When 和 运行 这段代码起初对我来说似乎没问题,控制台打印出来一个奇怪的字符:'�'(如果它不显示并显示为 space 这里是一个屏幕截图:https://prnt.sc/gbrp7b)控制台开始向它发送垃圾邮件,但如果我输入一个字符,它就会显示在输出中,但仍然是 '?' 垃圾邮件。这是代码:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
cout << "You entered : " << input << endl;
//break;
}
return 0;
}
所以我想尝试使用 if 语句来阻止它发送垃圾邮件,但代码无法识别该字符:
它给出了这个错误:
error: character too large for enclosing character literal type
对于此代码:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
if(input!='�'){
cout << "YOu entered : " << input << endl;
}
}
return 0;
}
我正在使用 OSX Sierra 10.12.5 并使用 eclipse Oxygen
您需要使用 initscr()
初始化 ncurses
并使用 endwin()
函数关闭它:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
initscr();
while (true) {
input = getch();
cout << "YOu entered : " << input << endl;
}
endwin();
return 0;
}