The Daily Click ::. Forums ::. Non-Klik Coding Help ::. vector probbies
 

Post Reply  Post Oekaki 
 

Posted By Message

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
1st July, 2004 at 07:23:15 -

hi,

i'm trying to learn about vectors in C++, but MSVC is being a bit anal about it. Anyone know why? Thanks...


#include <iostream>
#include <vector>

vector <int> test(50);

int main() {

system("PAUSE");

return 0;
}


Errors:
(4) error C2143: syntax error : missing ';' before '<'
(4) error C2501: 'vector' : missing storage-class or type specifiers
(4) error C2143: syntax error : missing ';' before '<'

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
1st July, 2004 at 07:33:33 -

Captain Optimistic to the rescue!
Actually, I don't know anything about C++.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Zane



Registered
  09/09/2003
Points
  1183
1st July, 2004 at 08:20:26 -

whats the <int> for between vector and test[50]?

ps-i know nothing about vectors, and only the bear bones of c++(though im getting the hang of it, allegro rocks) so this is a bit of a stab in the dark

 
www.klikforever.co.uk
GO THERE!!!

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
1st July, 2004 at 08:32:03 -

it's a nifty C++ feature called templates that let you make classes with member data/functions that take any kind of argument (int, in this case) so you don't have to do different versions of it (float,int, char etc)

oh and test is the name of the variable and 50 is the number of elements (Vectors are resizable arrays)

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
1st July, 2004 at 09:26:44 -

*looks back at notes on vectors*

hmm...your syntax appears correct.I'd say it's either the compiler or you don't have the vector header library installed.

The vector code I know is from a library called apvector:

#include "apvector.h"

Maybe you're not using the right library?

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
1st July, 2004 at 09:47:43 -

nevermind, i've got it, thanks

I was missing "using namespace std;". Didnt think i needed it

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
2nd July, 2004 at 14:25:47 -

A HELPFUL NOTE FOR PEOPLE:

You don't have to use 'using namespace std;', you can just use 'using std::vector;' or refer to it as std::vector if you're worried about any namespace conflicts

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
2nd July, 2004 at 15:21:46 -

nice one, thanks

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G
   

Post Reply



 



Advertisement

Worth A Click