#include <iostream>
#include <string>
#include <vector>
int main()
{
std::string s = "whatever\nyou want\nto have";
std::vector<std::string> vec;
std::size_t pos;
while( (pos = s.find('\n')) != std::string::npos )
{
vec.push_back( s.substr(0,pos) );
s = s.substr(pos+1);
}
vec.push_back(s);
// print out
for(pos = 0; pos < vec.size(); ++pos)
{
std::cout << "vec[" << pos << "] = \"" << vec[pos] << "\"" << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgoKaW50IG1haW4oKQp7CiAgICBzdGQ6OnN0cmluZyBzID0gIndoYXRldmVyXG55b3Ugd2FudFxudG8gaGF2ZSI7CiAgICBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gdmVjOwoKICAgIHN0ZDo6c2l6ZV90IHBvczsKICAgIHdoaWxlKCAocG9zID0gcy5maW5kKCdcbicpKSAhPSBzdGQ6OnN0cmluZzo6bnBvcyApCiAgICB7CiAgICAgICAgdmVjLnB1c2hfYmFjayggcy5zdWJzdHIoMCxwb3MpICk7CiAgICAgICAgcyA9IHMuc3Vic3RyKHBvcysxKTsKICAgIH0KICAgIHZlYy5wdXNoX2JhY2socyk7CiAgICAKICAgIC8vIHByaW50IG91dAogICAgZm9yKHBvcyA9IDA7IHBvcyA8IHZlYy5zaXplKCk7ICsrcG9zKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCAidmVjWyIgPDwgcG9zIDw8ICJdID0gXCIiIDw8IHZlY1twb3NdIDw8ICJcIiIgPDwgc3RkOjplbmRsOwogICAgfQp9