Tell me with editable default value in C ++?

Is it possible (without an external library, for example boost) to request input from the user, for example, using cin, but with a default choice that can be changed by the user (without a GUI)?

For example, the program will say:

Give your input: default

and the user can press "enter" to use "default", or press 1, then enter "default1", etc.

EDIT for clarification:

What I have in my program provides a default value at the prompt (as in one of the answers below). But I write for special cases where the editable default value is extremely economical (and in 90% of cases all user needs add a suffix to the default). I can only request a suffix, but then I lost the flexibility to change the default value in another 10% of cases.

+3
source share
3 answers

You might want to use the GNU readline .

+4
source

, . ( , ), , . :

Please enter a year (default: 2009):

Do you really want to exit (N):

: , , / , , , , , /.

.

+3

It’s not easy without an external library. All terminals handle this differently - if you do not want to write a lot of code, you will need a library. I suggest you take a look at Ncurses .

0
source

Source: https://habr.com/ru/post/1712201/


All Articles