user3111311
user3111311

Reputation: 8001

How to detect blank lines from istream in c++11?

How to detect blank lines from istream in c++11?

Is there a simple method, or I will have to do something like remove empty spaces and tabs and then see if the resulting string is empty?

Upvotes: 0

Views: 158

Answers (1)

Simple
Simple

Reputation: 14390

std::string s;
if (!std::getline(in, s)) {
    // There wasn't another line.
}
auto pred = [](unsigned char const c) { return std::isblank(c); };
if (std::all_of(s.begin(), s.end(), pred)) {
    // This line was empty.
}

Upvotes: 5

Related Questions