简体   繁体   中英

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

Hello I'd like to know how to get rid of the space created when printing a new line in c++ using ncurses library.

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

using namespace std;

int main(){

    initscr();
    noecho();

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

    endwin();

    return 0;
}

I have this output
Hello
----World

(The dashes are the space I mean)

Offhand, I'd expect this output:

Hello
     World

since curses puts the screen into raw mode, suppressing the cooked-mode feature that converts output line-feeds into carriage-return/line-feed. If you really want to print

Hello
World

you should use curses calls (which also happen to work with curses output buffering ):

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

Besides the misformatted output, mixing cout with curses can cause your output to be sent in a different order than the curses calls. That's what I meant by buffering .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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