This codes compiles and works as intended but the comment line doesnt for some reason can anybody tell me why.
std::cout << "Enter a line:\n";
const std::string Whitespace = " \t\t\f\v\n\r";
//std::string Line= std::string(Line.find_first_not_of(Whitespace),Line.find_last_not_of(Whitespace)+1); // Why doesnt this work?
std::string Line= Line.substr(Line.find_first_not_of(Whitespace),Line.find_last_not_of(Whitespace)+1);
std::cout << "You entered:" << Line << "\n";
Not only the commented line, but another will also fail if there is space in the begin of string.
First line fail (to compile) because
size_t. And construct
string from two size just make no sense.
Second line may fail because
string::substr accept length (not end) as it's second parameter.