Problem with vector, help :)
Apr 10, 2012 at 4:53am UTC
Im trying to use vectors in a server im making, but i dont understand them completely yet, i can compile my game, but when the event gets called, the program gets an error "Program has encountered an error and needs to close"
Ive got a picture of the debug window, that shows where the error is, here:
http://greencheesehotel.no-ip.org/images/problem.png
part of 'Packets.cpp' that screws up:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
int denyammount=0;
vector <int > denyreason;
if (fexists(fName.str().c_str()))
{
server::print("[" +plr->username+"]Somebody tried to create a already created account!" , game::c_red);
denyammount++;
denyreason[denyammount]=7;
//exists=1;
}
if (count_if(plr->username.begin(), plr->username.end(), isalnum) == plr->username.size()==false )
{
server::print("[" +plr->username+"] tried to register an account with invalid characters! " , game::c_red);
denyammount++;
denyreason[denyammount]=6;
//invalidcharacters=1;
}
if (plr->username.length()>13)
{
denyammount++;
denyreason[denyammount]=8;
//untoolong=1;
}
if (plr->username.length()<4)
{
denyammount++;
denyreason[denyammount]=4;
//untooshort=1;
}
if (plr->password.length()>13)
{
denyammount++;
denyreason[denyammount]=8;
//pwtoolong=1;
}
if (plr->password.length()<4)
{
denyammount++;
denyreason[denyammount]=5;
//pwtooshort=1;
}
start of 'Packets.cpp'
1 2 3
#include "packets.h"
#include "globals2.h"
string globals::version;
Please tell me how to make vectors work this way without bugging up :)
[SOLUTION]
Instead of using
i should be using
Last edited on Apr 10, 2012 at 5:54am UTC
Apr 10, 2012 at 5:21am UTC
google vectors. if you want to add an element to the end of the vector do
myvector.push_back(myinteger);
reference things in the vector the same way as you would an array
Topic archived. No new replies allowed.