Bogdan Maier
Bogdan Maier

Reputation: 683

Printing Vector Members. error

I need to sort then print the result increasing and decreasing. I have some problems with my printing.

Code:

 void srtAsc(Array M){
    vector <int> days[31];

for(int i=0; i<31; i++){
    int s=0;
    for(int j = 0; j<6; j++){
        s += M.M[i][j];
        days[i] = s; //// HERE

    }
 sort(days[0],days[31]);
 }
 for(int i=0; i<31;i++){
    cout<<i<<". "<<days[i]; ///// HERE 
    cout<<endl;
 }
  }

ERROR: ///// HERE spots I get also an error, maybe they are related. " No match oeprators '='

c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_algo.h:2072:4: error: no   match for 'operator--' in '--__next'
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_algo.h:2074:7: error: no match for 'operator*' in '*__last'

Upvotes: 0

Views: 86

Answers (1)

Lubo Antonov
Lubo Antonov

Reputation: 2318

STL algorithms, like sort, operate on iterators, so you will need to call sort like this:

sort(days.begin(), days.end());

But first, fix your code: you have created 31 vectors - not a vector with 31 elements. Use

vector<int> days(31);

Upvotes: 2

Related Questions