I am trying to do something like this:
BOOST_FOREACH (const std::string& line, allLinesOf(someFileLoadedIntoString))
{
...
}
I wonder how to implem开发者_JS百科ent the allLinesOf function? Thanks!
UPDATE: Thanks for the answers. Sorry but I forgot to mention one important detail: in my case the newlines are \r\n.
You can use std::getline.
std::string line;
while(std::getline(file, line)) {
// Ohai!
}
Um, you can write a custom iterator for std::string that would iterate over string segments separated by newlines and pass a std::pair of such iterators to BOOST_FOREACH
You can use boost::tokenizer with \n
token to iterate over lines.
精彩评论