1
我是C++和向量的新手,一直試圖使用一些STL函數進行實驗,並且想知道這是怎麼回事。我猜是因爲我的第一個和最後一個位置,他們是不是被允許進入?向量和使用STL
#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;
/*
*
*/
int main() {
const int lowest = 10;
const int highest = 99;
vector<int> scramble;
for (int i = 0; i < 20; i++){
scramble.push_back(lowest + rand() % (highest - lowest + 1));
cout << scramble.at(i) << endl;
}
int first = 0;
int last = 19;
cout << "The maximum value is: " << max_element(first, last);
}
什麼是 「不工作」? – GManNickG 2013-05-07 23:56:11
'max_element(first,last);'我猜我必須使用迭代器而不是整數或什麼? – user1719605 2013-05-07 23:58:07
嘿,是的。 「max_element」應該如何知道你需要'scramble'的最大值而不是其他矢量? – 2013-05-08 01:37:55