为什么输出的每一行之前都有不必要的空格?

Why is the ouput having unnecessary blank spaces preceeding every line?

我编写了一个 C++ 程序来打印用户在按下回车键后输入的所有内容,因此在此之前他不会看到他输入的内容。下面是代码:

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

using namespace std;

int main() {
    char c, printText[10000];
    int key, i;

    initscr();
    refresh();
    noecho();

    while(1) {
        c = getch();
        key = c;        
        if( key == 10 ) {
            cout<< printText << endl;
            memset( printText, 0, sizeof(printText) );
            i=0;
        }
        else 
            printText[i++] = c;
     }

    endwin();
}

此代码给出以下输出:

根据要求的输出仅在用户按下 enter.But 后出现,如您所见,输出中从第二行开始的每一行之前都出现了空格,这是不需要的。我无法理解为什么输出中会出现这些空格,我应该如何避免这种情况?请指导。

您正在将 curses 输出和 iostream 输出混合到同一设备。使用一个或另一个,否则你会发生不可预测的奇怪事情,就像你所看到的那样。