Default input value

Is it possible to create a default input value that will display the default value in a console window?

For example, have an input value of:

Input:

And the default value will be:

Input: Default Value

The default value will be displayed and the user can press backspace to clear if they want to change, otherwise just press enter.
Does this look good?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int a=17;

    string input;

    cout << "enter a (hit enter for default=17): ";
    getline(cin,input);

    if (input.length()>0)
    {
        stringstream(input)>>a;
    }

    cout << "a=" << a << endl;

    cout << "\nhit enter to quit...";
    cin.get();
    return 0;
}

Info on string -> http://cplusplus.com/reference/string/string/
Info on stringstream -> http://cplusplus.com/reference/iostream/stringstream/
Yes, that looks good enough, that's pretty much where I'm at. I was thinking it would be nice to have a value such as "17" that will actually display and can be edited.

enter a: 17

Where 17 can be edited and will be displayed on the input line.
Topic archived. No new replies allowed.