It returns whether the string is empty (i.e. whether its length is 0).
DeclarationFollowing is the declaration for std::string::empty.
bool empty() const;C++11
bool empty() const noexcept;Parameters
none
Return Valueit returns true if the string length is 0, false otherwise.
Exceptionsif an exception is thrown, there are no changes in the string.
ExampleIn below example for std::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 above was:\n" << content; return 0; }
The sample output should be like this −
Please introduce a text. Enter an empty line to finish: sairamrkshna mammahe The text you introduced above was: sairamrkshna mammahe
string.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4