Having issue

closed account (4LC4GNh0)
How do I input file string seperated by commas and print. The string needs to stop after each comma. Having trouble trying to figure out the correct method. This is what I have so far.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()

{
	ifstream inData;
	inData.open("TextFile1.txt");


	string j;
	string p;
	string c;
	string h;

	

	cin >> inputfile;
	inData.open("TextFile.txt");
	inData.get(j);
	
	inData >> j >> p >> c >> h;
	inData.ignore(200,',');

	inData.get(p);
	inData.ignore(200,',');

	inData.get(c);
	inData.ignore(200,',');

	inData.get(h);
	inData.ignore(200,',');
	

	

	cout << " The first three words we found are...\n";
	cout << j << p << c << h << endl;
	/*cin.ignore(200,',');
	cout << p;
	cin.ignore(200,',');
	cout << c;
	cin.ignore(200,',');
	cout << h;*/
	inData.close();
	 
	system ("pause");

	return 0;

}
Use the third argument of std::getline:
1
2
std::string blah;
std::getline(inData, blah, ',');
http://www.cplusplus.com/reference/string/string/getline/
http://en.cppreference.com/w/cpp/string/basic_string/getline
Topic archived. No new replies allowed.