I'm working on a program, and what I'm trying to do is have the TempVec assigned to a multidimensional vector, but that's where I get stuck.
Basically, the TempVec is read in from a line from a .txt file. All the spaces are removed, and then each line from the .txt file is supposed to be added to a row of the multidem vector.
There's a header file and a driver file, but those don't matter.
Code:
vector<string>TempVec;
ifstream InStream;
InStream.open( FileName.c_str(), ios::in );
int pos = 0;
string str, word;
if(!InStream.fail())
{
while(!InStream.eof())
{
getline(InStream, str);
string::size_type pos = str.find(" ");
string::size_type pos2 = 0;
while (pos != string::npos)
{
word = str.substr(pos2, pos - pos2);
if(word != "")
cout << word << " ";
TempVec.push_back(word);
pos2 = pos + 1;
pos = str.find(" ", pos2);
//pos2 = str.find_first_of("\n", pos2 + 1);
}
cout << str.substr(pos2, str.size()-pos2) << endl;
}
}
else{
cerr << "Unable to read from " << FileName << endl;
}
InStream.close();
Thanks for your input; I have not been able to think up a solution.