public member function
<string>
bool empty() const noexcept;
Test whether string is empty
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// string::empty
#include <iostream>
#include <string>
int main ()
{
std::string content;
std::string line;
std::cout << "Please introduce a text. Enter an empty line to finish:\n";
do {
getline(std::cin,line);
content += line + '\n';
} while (!line.empty());
std::cout << "The text you introduced was:\n" << content;
return 0;
}
| |
This program reads the user input line by line and stores it into string content until an empty line is introduced.
Complexity
Unspecified, but generally constant.
Constant.
Iterator validity
No changes.
Data races
The object is accessed.
Exception safety
No-throw guarantee: this member function never throws exceptions.