繁体   English   中英

使用c ++和ncurses中的标准输出打印新行时摆脱空间

[英]Get rid of space when printing a new line using standard output in c++ and ncurses

您好,我想知道如何使用ncurses库在c ++中打印新行时摆脱创建的空间。

#include <iostream>
#include <ncurses.h>

using namespace std;

int main(){

    initscr();
    noecho();

    cout << "Hello" << endl;
    cout << "World" << endl;

    endwin();

    return 0;
}

我有这个输出
你好
- - 世界

(破折号是我指的空格)

临时而言,我期望此输出:

Hello
     World

由于curses将屏幕置于原始模式,因此抑制了将输出换行转换为回车/换行的熟模式功能。 如果您真的要打印

Hello
World

您应该使用curses调用(也可以 curses输出缓冲中使用 ):

addstr("Hello\n");
addstr("World\n");

除了格式错误的输出外,将cout与curses混合使用可能会导致您的输出以不同于curses调用的顺序发送。 这就是缓冲的意思。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM