Group string by first integer

I want to print out CourseName by the first integer of the CourseCode. How can I do that?

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
55
56
57
58
59
60
61
62
63
64
// Simple code to store courses using vectors and strings

#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(void)
{
	const string DegreeCode("PHYS");
	vector<string> VectorOne;
	string CourseCode;
	string CourseTitle; 
	const string CompareString("done"); 
	bool ExitLoop;
	int i=0; 
	string CourseName; 
	
	ExitLoop = false;
	
	do
	{
		cout << "Enter course code (enter 'done' to exit): ";
		getline(cin,CourseCode);
		
		if (CourseCode==CompareString)
		{
			ExitLoop = true;
		}
		
		else
		{
			cout << "Enter course title: ";
			getline(cin,CourseTitle);
			CourseName=DegreeCode+CourseCode+CourseTitle;
			VectorOne.push_back(CourseName);
			i=i+1;
		}
	}
	while(!ExitLoop);
	
	cout<<"Unsorted list"<<endl;
	vector<string>::iterator iter;
	for (iter = VectorOne.begin(); iter != VectorOne.end(); iter++)
	{
		cout << (*iter) << endl;	
	}
	
	cout<<"Accending list"<<endl;
	sort (VectorOne.begin(), VectorOne.end());     
	for (iter = VectorOne.begin(); iter != VectorOne.end(); iter++)
	{
		cout << (*iter) << endl;
	}
	
	
	getc(stdin);
		
	return 0;
}
What is "the first integer of the CourseCode"?!
i suggest u make use of STL container Map instead of vector, map holds data as key value pair, then u can access the course name based on course code.
Topic archived. No new replies allowed.