Re: Preset text for cin
No, but you could wrap the concept into a function template
This is untested pseudo code, just to illustrate
Code:
template<T> GetValueWithDefault( T &o, T &n )
{
T newVal;
cout<<"Old value is: "<< o <<" New value: ";
cin >> newVal;
if ( IsNull( newVal ) )
{
newVal = o;
cout << o;
}
}
This code assumes you have an overload for a function IsNull which can evaluate any type T for "no entry" from cin.
The idea is simply to provide a function that takes the input, checks to see if nothing was entered, and output the default provided. Many variations on the theme are possible.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
Bookmarks