You may use a map whoose key is a string containing the name and whose value is a vector of string (each of the latter containing one of 'value1', 'v_alue2_', etc...). For instance:
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// the map containing the 'name' and a vector of 'value's
map <string, vector <string > > item;
const int SIZE=0x100;
char buf[SIZE];
ifstream ifs("foo.txt");
while (ifs.getline(buf,SIZE).good())
{
size_t m, n;
string s(buf);
string name;
vector <string> value;
if ( (m=s.find('\t')) != string::npos)
{
name = s.substr(0,m);
while ((n=s.find(' ',m+1)) !=string::npos)
{
value.push_back( s.substr(m+1,(n-m)));
m=n;
}
value.push_back(s.substr(m+1));
item.insert(make_pair(name,value));
}
}
// now dump all found items
map <string, vector <string > >::iterator itm;
for ( itm = item.begin(); itm != item.end(); itm++)
{
cout << "name = " << itm->first << endl;
vector <string>::iterator itv;
for ( itv = itm->second.begin(); itv != itm->second.end(); itv++)
{
cout << '\t' << *itv << endl;
}
}
}
Please note: code should be made more robust (it isn't robust at all). That's left as exercise to the reader. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]