2012-03-29 56 views
0

我需要排序然后打印结果增加和减少。我的印刷有一些问题。打印矢量会员。错误

代码:

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; 
} 
    } 

错误: ///// HERE点我也得到一个错误,也许他们是相关的。 “不匹配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' 
+3

你知道你创建了一个31个向量的数组而不是一个向量机智h容量为31? – Joe 2012-03-29 12:38:13

+1

什么是数组?请发布[** minimal ** test-case](http://sscce.org)和** complete **错误消息。 – 2012-03-29 12:39:11

+0

WooaaA? :))seriosly?它不是矢量名称该模板? – 2012-03-29 12:39:21

回答

2

STL算法,如sort,操作上迭代,所以你需要调用sort这样的:

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

但首先,解决您的代码:你已经创建了31个向量 - 不是一个有31个元素的向量。使用

vector<int> days(31); 
+0

它适用于我没有错误/ BUG在那里..有一个问题,当我尝试从我的数组M的值分配给矢量。 \t \t \t s + = M.M [i] [j]; \t \t \t days [i] = s; 当我尝试rpint向量它有=运算符的东西。 – 2012-03-29 12:44:32

+0

天[i] = s失败,因为天[i]的类型为矢量而不是int。这就是我正在谈论的错误的重点。 – 2012-03-29 12:50:17

+0

固定...你能给他们一个提示如何解决int adn vec 之间的差异?所以我可以将它们从M移动到几天? – 2012-03-29 13:19:26