I have the following code
Code:
//p.345 ex1
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <list>
#include <vector>
#define RND_RANGE 10000
#define TIMES (RND_RANGE)
using namespace std;
int main(void){
srand(time(NULL));
//generate 10,000 numbers between 0 and 9,999
list<int> the_list;
list<int>::iterator iter;
vector<int> freqs;
vector<int>::iterator p;
//place in list<int> container
for(int i = 0; i < TIMES; i++){
int j = (rand() % RND_RANGE);
the_list.push_back(j);
}
//iterate over values and display them
int x = 0;
for(iter = the_list.begin(); iter < the_list.end(); iter++){
cout << "item: " << x << " = " << *iter << "..." << endl;
if(x % 10 == 0)
cin.get();
x++;
}
//print the median value
//computer number freqencies
return 0;
}
when I comile it i get an error namely
Code:
/usr/include/c++/4.7/bits/stl_list.h:1603:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
/usr/include/c++/4.7/bits/stl_list.h:1603:5: note: template argument deduction/substitution failed:
p345no1.cpp:33:51: note: ‘std::list<int>::iterator {aka std::_List_iterator<int>}’ is not derived from ‘const std::list<_Tp, _Alloc>’
is what I'm thinking is most significant.
My question is it not possible to use
Code:
for(iter = the_list.begin(); iter < the_list.end(); iter++)
do you have to use the synatx
Code:
for(iter = the_list.begin(); iter != the_list.end(); iter++)
why is that? I assumed since i was iterating over it like a pointer using the increment operators it was probably stored in contiguous memory. Could have sworn I saw the < and > operators used to test it before.