std::cin and terminal auto completion??

N

none

I have an app where I need to read input from the user:

std::string setting;
std::cout << "Specify Path to setting :";
std::cin >> setting;


When I run this code I can manually type the path to the relevant file. But I cannot use eg. Tab to
auto-complete the current path I am typing.

How do I enable tab auto-completion when using std::cin ?
 
A

Alf P. Steinbach

* none:
I have an app where I need to read input from the user:

std::string setting;
std::cout << "Specify Path to setting :";
std::cin >> setting;


When I run this code I can manually type the path to the relevant file.
But I cannot use eg. Tab to auto-complete the current path I am typing.

How do I enable tab auto-completion when using std::cin ?

std::cin does not support that, or any particular interactive feature.

Your operating system shell may provide this feature.

In Windows that means configuring console windows, which you can do by
right-clicking the title bar of a console window.


Cheers & hth.,

- Alf
 
R

Robert Fendt

When I run this code I can manually type the path to the relevant file. But I cannot use eg. Tab to
auto-complete the current path I am typing.

How do I enable tab auto-completion when using std::cin ?

You don't, actually. Standard input is not concerned with 'what'
it is reading, that's the whole point. Because of that, there's
no support for that functionality in the C++ standard library.

If you want auto-completion features, you will have to either
configure the terminal running the program to do it, or you have
to use a library. GNU readline is a popular choice on Unix
systems, but it has the 'problem' that it is GPL'd (i.e., you
cannot use it in closed-source applications). Another choice
might be 'editline' (http://www.thrysoee.dk/editline/), though I
have no experience with it. Both libraries are plain C, as far
as I know, but should be usable from C++ without major problems.

Regards,
Robert
 
J

Jorgen Grahn

You don't, actually. Standard input is not concerned with 'what'
it is reading, that's the whole point. Because of that, there's
no support for that functionality in the C++ standard library.

If you want auto-completion features, you will have to either
configure the terminal running the program to do it, or you have
to use a library. GNU readline is a popular choice on Unix
systems, but it has the 'problem' that it is GPL'd (i.e., you
cannot use it in closed-source applications). Another choice
might be 'editline' (http://www.thrysoee.dk/editline/), though I
have no experience with it. Both libraries are plain C, as far
as I know, but should be usable from C++ without major problems.

Since he seems to be on Unix, he can also use that wrapper program
which provides command-line editing while running the actual application
as a subprocess. I think it's this one:

rlwrap - readline feature command line wrapper

Not on topic here, except it might save the poster a lot of
C++-related work.

/Jorgen
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top