Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt with editable default in c++?

Is is possible (without external library such as boost) to prompt for input from the user, like using cin, but with a default choice that is editable 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 to get "default1", etc.

EDIT for clarification:

What I current have in my program is providing the default in the prompt (as in one of the answer below). But I'm writing for very special cases where having a editable default is extremely time saving (and 90% of the time, all the user needs is adding a suffix to the default). I can prompt for the suffix only, but then I lost flexibility to edit the default in the other 10% of the cases.

like image 780
polyglot Avatar asked Sep 06 '25 11:09

polyglot


1 Answers

You may want to use GNU readline.

like image 91
Matt K Avatar answered Sep 08 '25 17:09

Matt K