I'm trying to port an app to Linux that makes use of some of the STD containers. I'm having a problem with the vector .at() method. The error I get is:
$ g++ -o testSTL testSTL.cpp
testSTL.cpp: In function `int main ()': testSTL.cpp:20: no matching function for call to `vector<int, allocator<int> >::at (int)'
This is from some small test code I got from "C++ How to Program" (code included below)
It looks to me like the STL implimentation provided with GCC 2.96 (provided by RedHat LInux 7.2) simply doesn't support that method. Is that the case? I can upgrade, if that will make a difference.
This sure looks like a classic RTFM, but I"ve spend hours on the net, and have not found a FM to read, so a pointer to some description of what the libraries with various versions of GCC provide in the way of STL support would be much appreciated.
-thanks,
-Chris
**** Simple test program below ****
#include <iostream> #include <vector> #include <algorithm>
using namespace std;
int main() { const int SIZE = 6; int a[ SIZE ] = {1,2,3,4,5,6}; vector< int > v(a, a + SIZE); ostream_iterator< int > output (cout, " " ); cout << "Vector v contains: "; copy( v.begin(), v.end(), output );
cout << "\nFirst element of v: " << v.front() << "\nLast element of v:" << v.back();
v [ 0 ] = 7; v.at( 2 ) = 10;
v.insert (v.begin() + 1, 22);
cout << "\nVector v after Changes: "; copy( v.begin(), v.end(), output );
v.erase( v.begin() ) ;
cout << "\nVector v after erase: "; copy( v.begin(), v.end(), output );
v.erase( v.begin(), v.end()) ;
cout << "\nVector v after erase all: "; copy( v.begin(), v.end(), output );
v.insert( v.begin(),a, a + SIZE ); cout << "\nContents of Vector before clear: "; copy( v.begin(), v.end(), output );
v.clear(); cout << "\nContents of Vector after clear: "; copy( v.begin(), v.end(), output ); // cout << "\n";
cout << endl;
return 0;
}
-- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@xxxxxxxx