c++ - Reading a file where middle name is optional -


i'm trying read in file formatted

firstname middlename(optional) lastname petname\n

with middle name being there on half entries, i'm unsure best way read these in , them correct variable names. appreciated.

you this:

std::string line, word; while (std::getline(myfile, line)) {     if (line.empty()) continue;              // read words line:     std::istringstream is(line);     std::vector<std::string> words;     words.reserve(4);     (int = 0; >> words && < 4; i++)         words.push_back(word);      if (words.size() == 4)         // middle name present ...     else         // not ... } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -