Mail Archives: djgpp/2003/11/03/09:46:20
"leila" <gcceducate AT tutorialwizard DOT net> wrote:
> Could someone please advise me what I?m doing wrong. I?m trying to
> use vector in a simple program. I'm using this command to compile
>
> gxx -Wall -o vectorTest.exe vectorTest.cpp
>
> But I get these errors:
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>> error <<<<<<
> vectorTest.cpp: In function `int main()':
> vectorTest.cpp:11: error: `vector' undeclared (first use this function)
> vectorTest.cpp:11: error: (Each undeclared identifier is reported only
> once for
> each function it appears in.)
> vectorTest.cpp:11: error: parse error before `(' token
> >>>>>>>>>>>>>>>>>>error <<<<<<<<<<<<<<<<<<<<<<<<<
>
> Here is the relevant part of the code, the error happens on the line I
> noted with ****
>
> >>>>> snip <<<<<<<<<<
> #include <iostream>
> #include <vector>
> using namespace std;
> int main()
> {
> int val[10] = {1,2,2,2,2,4,7,8,9,6};
> int saveVal;
> vector v1(val, val+10); // **** This is where the error starts
std::vector is a template, so you need to specify what type it
contains. In this case, it's int. The previous line should therefore
read:
vector<int>v1(val, val + 10);
As Mr. Broeker suggested, questions like this are probably better
directed to the comp.lang.c++ or comp.lang.c++.moderated newsgroups,
since this type of question isn't djgpp specific.
Best regards,
Tom
- Raw text -