i`m trying to get a string handler which takes input from user in a string type variable… but it is crashing and i would like to know why? or what am i doing wrong…
string UIconsole::getString(){
string input;
getline(cin,input);
if(input.empty() == false){
return input;
}
else{getString();}
return 0;
}
EDIT:
error:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
You have a couple of errors, but the specific one that the message refers to is this:
You can’t construct a
std::stringfrom a null pointer. If you want an empty string, try one of these contstructs:Your other error is the recursive call to
getString(). It isn’t at all clear what you are trying to do there. Maybe this does what you want: