Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > c++ initializing a vector - please help.

Thread Tools

c++ initializing a vector - please help.

chardane chardane is offline
Junior Member
Join Date: Jul 2010
Posts: 1
can anyone please look at this code and tell me what's wrong?

#include <iostream>
#include <vector>

int a[] = { 1,2,3,4,5,6,7,8,9,10 }; //array of 10

vector<int> gv(a, a + sizeof(a)/sizeof(*a));

int main {

for (int i = 0; i < gv.size(); i++) {
cout << "gv[ " << gv[i] << "] " <<endl;

it wont compile and it says:

vec.cpp:6: error: expected constructor, destructor, or type conversion before '<' token
vec.cpp:9: error: invalid function declaration

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Initializing a vector of a vector in a constructor C++ 4 11-12-2006 09:22 AM
Free memory allocate by a STL vector, vector of vector, map of vector C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM