0

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)

1 Answers1

0

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105