I have a very trival option processing function and i need to enter this function every so often. So i cant allocate the vector. I need to be able to add an element to the vector and save it so when i do come back to this function it is still their.
vector<sStruct> * loadFile(char *myTextFile)
{
myStruct
sStruct;
vector<myStruct>
vectorAddress,
vectorData;
vectorData = &vectorAddress;
string
feild1, feild2, feild3, feild4;
ifstream
*inFile = new ifstream;
inFile->open( myTextFile, ios::in );
if ( !inFile->good() )
{
cout << "? File Doesnt Exist! " << endl;
}
while ( !inFile->eof() )
{
// reading a file deliimted by commas hi,hello,hey,1234
//...
getline( *inFile, feild1, ',' );
sStruct.m_1 = field1;
getline( *inFile, feild2, ',' );
sStruct.m_2 = field2;
getline( *inFile, field3, ',' );
sStruct.m_3; = feild3
getline( *inFile, feild4 );
sStruct.m_4 = feield4;
// saving each member of the struct in the vector
vectorAddress.push_back( sStruct );
}
inFile->clear();
inFile->close();
cout << vectorAddress.size() << endl;
delete inFile;
//
(*vectorData) = vectorAddress;
return vectorData;
}
// This function tries despretly to add another element saved in struct member varaible
// to the end of the vector. I need the information from the first function to be here. What i think im trying to do is refer to the same address in memory.
vector<sStruct> * addElement(vector<sStruct> *vAddElement)
{
myStruct sAddElement; // referring to the same struct.
vector<sStruct> vectorAddress;
vAddElement = &vectorAddress;
cout << "Enter a String: ";
cin >> sAddElement.feild1 // save user spec in struct member
vectorAddress.push_back( sAddElement );
cout << vectorAddress.size() << endl;
(*vAddElement) = vectorAddress;
return vAddElement;
}
And im trying to do this without changing the function signuatures.