I would like to ignore empty line and line started with #

std::string line;  

while (getline(input,line))
{
  if (line[0] == '#') continue;

  if (line[0] == '?') continue;
  
...
}

Where ? is, I would like to put the end line character, but what is it in C++?

Recommended Answers

All 2 Replies

\n

You should do something like this :

const string& stringToAvoid = "#\n"; 
string line;
while(getline(cin,line)){
  if(stringToAvoid.find(line[0]) != string::npos) continue;
}

that way you can just add more character to stringToAvoid instead more if's

commented: Nice +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.