I have been stuck on this problem for a while, and I just can't figure it out. I'm sure there's an incredibly easy way to do it, but I'm at a loss...
I need to take in this text file:
Smith, M.N., Martin, G., Erdos, P.: paper name
Erdos, P., Reisig, W.: paper2 name
Smith, M.N., Chen, X.: paper3 name
Jablonski, T., Hsueh, Z.: paper4 name
Hsueh, Z.
Chen, X.
Smith, M.N.
The problem I have is that I can't get the file input right. I need it to stop at the ':', because the name of the paper isn't important to my algorithm.
struct Name {
string lastName;
string firstName;
};
int main()
{
Name n;
int num, P, V;
vector<Name> v1;
vector<Name>::iterator it;
string paper;
fstream myfile;
myfile.open("1.txt");
myfile >> num >> P >> V;
while (!myfile.eof())
{
myfile >> n.lastName >> n.firstName;
v1.push_back(n);
}
for (it=v1.begin();it!=v1.end();it++)
{
cout<<(*it).lastName<<(*it).firstName<<endl;
}
return 0;
}
I want to pass the 'Name' structure into a vector to compare, but I want only the last and first name. No commas.
Essentially, my problem is that I want to read the file up to the ':' and then ignore the rest. I feel like I've tried everything, but I just can't make it happen.
Any help is greatly appreciated!