在 c++ 和 ncurses 中使用标准输出打印新行时摆脱 space

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

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

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

using namespace std;

int main(){

    initscr();
    noecho();

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

    endwin();

    return 0;
}

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

(破折号是 space 我的意思)

顺便说一句,我希望这个输出:

Hello
     World

因为 curses 将屏幕置于原始模式,抑制了将输出换行符转换为 carriage-return/line-feed 的熟模式功能。如果你真的要打印

Hello
World

你应该使用 curses 调用(这也恰好可以工作 with curses output buffering):

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

除了格式错误的输出之外,将 cout 与 curses 混合使用会导致输出的发送顺序与 curses 调用的顺序不同。这就是我所说的缓冲