I would use
std::vector
and
std::istringstream
. The program
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
int main()
{
const std::string input = "Hello. My name is A.\nI am from B.\n";
vector <vector < string > > vline;
while ( true )
{
string line;
getline(cin, line);
if ( ! cin ) break;
vector <string> vword;
istringstream iss ( line );
while ( true )
{
string word;
iss >> word;
if ( ! iss ) break;
vword.push_back( word );
}
vline.push_back( vword );
}
cout << "{\n";
for (const auto & vw : vline)
{
cout << "{";
for ( const auto & w : vw )
{
cout << "\"" << w << "\", ";
}
cout << "},\n";
}
cout << "}\n";
}
fed with
Hello. My name is A.
I am from B.
produces
{
{"Hello.", "My", "name", "is", "A.", },
{"I", "am", "from", "B.", },
}
Such an output, while not exactly the one requested, it is an acceptable ( :-D ) imitation.