C++ help with Vectors please. Sorted vector is poof....????

Here's my code

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stdafx.h"  //don't worry about this line

#include <iostream>

#include <vector>

#include<algorithm>

using namespace std;

 bool myfunction (int i,int j) { return (i<j); }


struct myclass {

  bool operator() (int i,int j) { return (i<j);}

}myobject;

int main()

{

    vector<double> student_marks(05);

    for (vector<double>::size_type i = 0; i < 05; i++)

    {

        cout << "Please enter grades for student #" << i+1 

             << ": " << flush;

        cin >> student_marks[i];

    }

    // ... Do some stuff with the values

    //remove an element

    cout<<"Please enter the position where you would like the value to be removed \n";

    int i;

    cin>>i;

    student_marks.erase (student_marks.begin()+i-1);

    //displaying the vector

    cout << "My Vector Contains the following below:\n";

    for (unsigned i=0; i<student_marks.size(); ++i)

    cout << ' ' << student_marks[i];

    cout << "\n \n";

     cout<<"Sorted Vector contains \n \n";

    //sorting and displaying again

    std::sort(student_marks.begin(), student_marks.end());           


  // print out content:

  cout << "My Vector contains:";

    for (unsigned i=0; i<student_marks.size(); ++i)

    cout << ' ' << student_marks[i];

    cout << '\n';

	
	system ("Pause"); 
	
    return 0;

} 


My code compiles just fine. and i have no problem except for when i debug. Everything is fine but the part where it says: sorted vector contains: shows nothing. Any idea/help would be much appreciated. Should I increase the marks from 5 to 20 or something higher???? I'm alil confused what did I do wrong.

Thanks

Here's the initial question:

Create a simple program that manipulates vectors as follows:


Add a value to vector


Remove a value form vector


Display Vector


Sort vector
If the vector is displayed correctly before the sorting when I do not see any problem.
I'm sorry, I don't think i understand your statement. Perheps if you could rephrase it please.

Are you stating that if vector is displaying correctly then why am i sorting? or the sort is fine if its not showing any numbers??

Thanks
You display the vector before the sorting. Is it displayed correctly?
yes, the vector displays just fine.
It means that there is no any problem.
Last edited on
any problem???

Like what could possibly be any problem? any hints....
It was a typo. I updated my previous post.
Topic archived. No new replies allowed.