Say, something like this ...
id dob name 1 20000101 Jane Doe 5 19820611 Joe 4 19991202 Marlene Anne Robinson
Then you could have a struct like ...
struct Student
{
int id;
int dob;
string name;
} ;
Then you could hold all your data in a C++ vector
// a common C++ idiom is to code something like this ...
const string fName = "myData.txt";
ifstream fin( fName.c_str() );
if( fin )
{
vector < Student > v;
string line;
while( getline( fin, line ) )
{
istringstream iss( line );
Student s;
iss >> s.id >> s.dob; // skips leading ws
getline( iss, line); // get rest of iss line into line, preserve any leading ws
ltrim( line ); // trim off any leading ws
s.name = line; // add the name trimmed of leading ws
v.push_back( s ); // add this student struct to vector
}
fin.close();
}
else cout << "There was a problem opening file " << fName << endl;
This post has been edited by David W: 23 March 2013 - 10:27 AM

New Topic/Question
Reply





MultiQuote


|