How do I empty a string to obtain an empty line whe I "cout" it?
Printable View
How do I empty a string to obtain an empty line whe I "cout" it?
Do you mean you want to write a blank line to the screen? Try:
cout <<endl;
hehe ;) - sorry, but that's not the problem.
The string is returned by a function an only in certain cases it must be empty...
so I need to return an EMPTY string:needs to give me the spare line.Code:cout << string << endl;
Well if it's a std::string, I suppose:
std::string * s = new string(" ");
For a char array, do:
strcpy(s, " ");
You can use
in case where an empty std::string is to be returned.Quote:
return "";
@ Sebastiani: that's it - thank you :)
Functions clear() and erase() in the string class as well as over assignment operators do not assume that you want to clear everything from a string when you use one of the functions or the operator. From an STL string class perspective, a string object can hold more than just characters.
One solution is to set the string object array to NULL and then call clear().
KuphrynCode:string sText;
// Get a line of data from cin buffer.
// getline() terminates on ENTER key.
std::getline(cin, sText);
// Clear the entire object.
sText[sText.size()] = NULL;
sText.clear();