I'm sure that this will be a simple matter for the majority of you but I hope you'll bear with my simple inquiry and if I'm posting in the wrong place I would certainly like to know that as well.
Here Goes:
I have a list in a text file that is formatted like so:
firstName lastName
Position
firstName lastName
Position Position
...........
Position can be one or two words.
I'm tryin to read the file into 3 arrays one for the first and last names and one for the positions.
But I never get a good result" if position has more than 1 word.
Here's what I'm trying so far:
(As you can see by the remmed statements I've been playing with peek() and ignore() trying to find a solution. )
I sure would appreciate an assist on this. TIA
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
char peeking[9];
string first[9];
char sentry;
string last[9];
string position[9];
fstream inFile;
inFile.open("team1.txt");
for(int test = 0; test < 9; test++)
{
inFile >> first[test];
inFile >> last[test];
//inFile.ignore(0,'/n');
//peeking[test] = inFile.peek();
getline(inFile,position[test]);
}
for(int test = 0; test < 9; test++)
{
cout << "this is first " << test << " - " << player[test] << endl;
cout << "this is last" << test << " - " << garbage[test] << endl;
cout << "this is position " << test << " - " << position[test] << endl;
}
cin.get(sentry);
return 0;
}