【发布时间】:2016-05-11 20:42:06
【问题描述】:
#include <curses.h>
#include <fstream>
int main(){
initscr();
mvwprintw(stdscr, 1,1, "hello world");
wmove(stdscr, 1,1);
chtype* p = 0;
int n = 0;
n = winchstr(stdscr, p);
std::ofstream test("test.txt");
test << n << " " << (p == nullptr);
endwin();
}
在上面我打印hello world,将光标移回句子的开头,并尝试使用winchstr将屏幕上的内容存储到p。除了在文件test.txt 中,我只看到输出-1 1 暗示p 没有改变并且ERR(即-1)被返回,正如documentation 所描述的那样:
int winchstr(WINDOW *win, chtype *ch);
说明: 这些例程从窗口中读取一个 chtype 或 cchar_t 字符串, 从当前或指定位置开始,到 右边距,或在 n 个元素之后,以较小者为准。
返回值: 所有函数都返回读取的元素数,或 ERR on 错误。
我是否误解了文档?以hello world 开始的行的内容在使用winchstr 后应该存储在p 指向的位置不应该吗?为什么返回错误?
【问题讨论】: