Sorting integers

I need to read a list of integers from a file and store it into a vector.

int main()
{

string temp;
vector<int> x;
ifstream infile;

infile.open("numbers.txt");

if(infile)
{
while (getline(infile, temp))
{
stringstream(temp) >> num;
x.push_back(num);
}
infile.close();
}

The code I have so far allows me to read the numbers from the file and store the numbers into the vector, however I also need to find the numbers from the file that are repeated and the number of times the numbers are repeated.
I will not be able to use the algorithm library as we have not yet covered it in class, I was instructed that I should insert in a way that it is ordered but I have not a clue of how to approach.
Any help would be greatly appreciated.
Thank you keskiverto, however I will not be able to use any of the functions in the algorithm library as the professor has not yet gone over them. This is just a beginner class and we've only covered simple material :(
I said "use the idea" described on that page. What does the std::upper_bound do?

How would that help you insert so that vector remains sorted?

Obviously, you won't be using the library functions, but write your own.
you can implement by similar idea of the program
it inserts numbers sequentially in a vector
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
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	vector<int>vect {1,5,9,14}; // sorted
	int arr[3] = {5,2,15}; // not sorted // insert arr in vect ascending
	int arrsize = 3;
	
	int index;
	for(int i=0; i<arrsize; i++)
	{

		for( index=0; index<vect.size() ; index++) 
		{
			if(arr[i] >vect.at(index) )
				continue;
			else break;	
		}

		if(index<vect.size()) vect.insert( begin(vect) + index, arr[i]);
		else vect.push_back(arr[i]);
	}
	
	cout << "vect size = " << vect.size() << endl; // 7 
	
	for(auto x: vect)
	{
		cout << x << " ";  // 1 2 5 5 9 14 15
	}

return 0;
}
Topic archived. No new replies allowed.