Array Help?

Basically I'm trying to filter out names from a text file. So the given text file would be in the format of --
Jim, Doe
Jane,Deer
Ronald, Mc Donald

And the output is only the last name. All i have so far is getting the text into arrays. I believe to solve this i have to detect the comma and basically output anything after that but I have no clue how to.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using namespace std;
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

int main()
{
	char line [50];
	ifstream file;
	file.open ("50student.txt");
	if(file.is_open())
	{
		while(!file.eof())
		{
			file.getline(line,sizeof(file));
			
			cout<<line<<endl;

		}
		file.close();
	}
		
	system("pause");
}
You can do this by changing the delimiter that getline uses. getline uses the '\n' as it's normal delimiter. Meaning it inputs a string until it gets to a newline character. If you use the statement getline(inputfile, string, ','); getline will retrieve a string up to the first occurance of a comma. Then you can use another getline with '\n' as the delimiter to get the rest of the line, and discard the part you don't want.
Ok I figured it out thanks
Topic archived. No new replies allowed.