need to modify location of text output and input on screen in consolenative c++ application

M

matthew.pugsley

Hello,

The following question concerns printing out some output and then
repositioning the cursor for input.

I am creating a native c++ console application. I would like to have
the user input a number of data items of type double. One way to do
this would be:

double jan, feb, mar;

cout << "Jan: ";
cin >> jan;
cout << "Feb: ";
cin >> feb;
cout << "Mar: ";
cin >> mar;

This would work, but well, it just looks clunky to me. It'd look more
polished to print out

Jan:
Feb:
Mar:

And then reposition input on the screen so that the user type a number
next to Jan, presses enter, then enters a number a next to Feb,
presses enter, then ... etc. until done.

I realize I could also use getline() for the input, but that doesn't
solve the problem of positioning input.

Also, I understand that there are lots of functions for peeking,
ignoring, etc. bits of input. But my understanding is that this just
allows you to play with the input buffer and read different parts of
the buffer into different variables. That has nothing to do with
controlling the location of screen output.

I also understand that a library for creaing guis with console
applications called "ncurses" exists for compiling on Unix-like
systems. But I'm using Microsoft Visual C++ 8 Express Edition on a
Windows Vista machine. So I can't use that.

I've tried many searches on Google and this newsgroup (variations of
"output around input", "control text location output native c++",
etc.). But no luck.

Can anyone point me in the right direction? Explanations or pointers
to a website tutorial would be equally welcome.

Thank you in advance!

Matthew Pugsley
 
M

matthew.pugsley

Hello,

The following question concerns printing out some output and then
repositioning the cursor for input.

I am creating a native c++ console application. I would like to have
the user input a number of data items of type double. One way to do
this would be:

double jan, feb, mar;

cout << "Jan: ";
cin >> jan;
cout << "Feb: ";
cin >> feb;
cout << "Mar: ";
cin >> mar;

This would work, but well, it just looks clunky to me. It'd look more
polished to print out

Jan:
Feb:
Mar:

And then reposition input on the screen so that the user type a number
next to Jan, presses enter, then enters a number a next to Feb,
presses enter, then ... etc. until done.

I realize I could also use getline() for the input, but that doesn't
solve the problem of positioning input.

Also, I understand that there are lots of functions for peeking,
ignoring, etc. bits of input. But my understanding is that this just
allows you to play with the input buffer and read different parts of
the buffer into different variables. That has nothing to do with
controlling the location of screen output.

I also understand that a library for creaing guis with console
applications called "ncurses" exists for compiling on Unix-like
systems. But I'm using Microsoft Visual C++ 8 Express Edition on a
Windows Vista machine. So I can't use that.

I've tried many searches on Google and this newsgroup (variations of
"output around input", "control text location output native c++",
etc.). But no luck.

Can anyone point me in the right direction? Explanations or pointers
to a website tutorial would be equally welcome.

Thank you in advance!

Matthew Pugsley

I now see this item in the FAQ:
[15.19] How can I move the cursor around on the screen?
This is not a standard C++ feature — C++ doesn't even require your
system to have a screen. That means every operating system and vendor
does it somewhat differently.

Please read the documentation that came with your compiler for details
on your particular installation.

[ Top | Bottom | Previous section | Next section | Search the FAQ ]

I will start looking through the documentation. But if anyone has
already achieved this and can share a tip, please do! Thank you!
 
P

Peter Remmers

Hello,

The following question concerns printing out some output and then
repositioning the cursor for input.

>> [...]

As you already found out, the language only assumes "dumb terminal" output.

For full screen text output you'd have to use OS-specific functions
(SetConsoleCursorPosision) or an abstracting text UI library such as
ncurses.

There is a windows port of the curses library, called "pdcurses".

There's also the possibility of fully-fledged TUI libraries, such as
tvision, but this might be overkill for your needs.
 
M

Matthew

 >> [...]

As you already found out, the language only assumes "dumb terminal" output.

For full screen text output you'd have to use OS-specific functions
(SetConsoleCursorPosision) or an abstracting text UI library such as
ncurses.

There is a windows port of the curses library, called "pdcurses".

There's also the possibility of fully-fledged TUI libraries, such as
tvision, but this might be overkill for your needs.

Thanks, Peter!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top