or in c++, simply call getline? i haven't traced thru your code, but i would not be surprised if there were errors in it, having written similar stuff myself.
compare with using std::string and std::getline - easy to use and battle-hardened.
compare with using std::string and std::getline - easy to use and battle-hardened.
What would the equivalent code look like in C++, handling EOF and OOM conditions appropriately?
string input;
try {
if ( cin.getline ( input ) ) {
// ok read input, do something with it
}
else {
// some sort of predictable error - look at state of cin to diagnose EOF
}
}
catch (...) { /// something terrible happened - as hard to recover as it would be in c
}