Reading using getline

What i need to do is read in a line, take the first 4 to see if a class is being offered, then the rest of the line is the name of the course. The name varies in length and i am unsure of how to get it all.

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
const int F15 = 8, S16 = 4, F16 = 2, S17 = 1;
		std::ifstream inFile;
		std::string path = "C:\\Users\\Lord Brebo\\Desktop\\BCS-courses.txt";
		std::vector<string> course; //course ID
		std::vector<int> value; //value of semester EX:8,4,2,1 for f15,s16,f16,s17
		int codes[] = { F15,S16,F16,S17 };
		std::string a, b, c, d, e, BCS, num, title;
		std::string X = "X";
		int rcd, i, sum;
		inFile.open(path);

		if (!inFile)
		{
			cout << "file not found:" << path << endl;
			return -1;
		}

		i = 0;
		rcd = 0;
		getline(inFile, e);
		inFile >> a;
		while (inFile.getline)
		{
			sum = 0;
			inFile >> b >> c >> d >> BCS >> num >> title;
			BCS = num + " " + title;
			//course[i] = BCS;
			if (a == X)
			{
				sum += F15;
			}
			if (b == X)
			{
				sum += S16;
			}
			if (c == X)
			{
				sum += F16;
			}
			if (d == X)
			{
				sum += S17;
			}
			std::cout << sum << " " << BCS << std::endl;
			inFile >> a;
			++i;
			++rcd;
		}
		inFile.close();
		return 0;
	}


the file begins like this:
1
2
3
F15 S16 F16 S17 
 .   .   .   .   BCS 101 Programming Concepts and Problem Solving
 X   X   X   X   BCS 102 – Computer Concepts & App

Last edited on
one way might be to use string.erase
read the line
copy it to string1 and string2
erase what you don't want from each line.
Topic archived. No new replies allowed.