Hello, I am trying to read some words from section in an INI file.

Then putt hem into a vector of a section vector,

This is the struct and class def

struct  elgbotsections_t
{
	char name[30];
	vector <string> phrase;
};

class ElgbotManager
	{
	private:
		char * filename;
	public:

		ElgbotManager( ) { }
		~ElgbotManager( ) { }

		qboolean Initialize( );
		
		vector <elgbotsections_t> elgbotsections;

then i try to fill the elbotsections like so:

//each section
	char *sections[]={
	"gotkill",
	"headshot",
	"torso",
	"pelvis",
	"rightarm",
	};
//just to mess witht he int to str
	char buffer [33];


//for each section
	for(section = 0;section <= 4; section++)
	{
//elgkey should be named elgsection 
// 

//make a section and set its name to the section name
		elgbotsections_t elgkey;
		strcpy(elgkey.name, sections[section]);

//for each key in that section
// set a key in the vector of strings
		for(i = 1;i <= 25; i++)
		{
			itoa (i,buffer,10);

			strcpy (key,"word" );

			strcat (key, buffer );

			feedback = settings.ReadString(sections[section],key,NULL);
	
			if(strlen(feedback))
			{
//make a string and add it to the phrase vector (vector of strings)
				string skey;
				skey.assign(feedback);
				elgkey.phrase.push_back(skey);
			}
			else
			{
				break;
			}
		}
	
//now add this section vector to the list of section.
		elgbotsections.push_back(elgkey);
	}


print();

now to test it worked ok...i tried printing them

void ElgbotManager::print( )
{
	
	long i;

	long o;
	for(i =0; i <= elgbotsections.size(); i++);
	{

		elgbotsections_t l;

//this following line CRASHES
	        l = elgbotsections.at(i);

//without trying to access the at...it works..
// .size appears to be 1 section with 1 key
// from the prints "section"

//from the INI it should be at least 2 sections 
// and 2nd having 3 words.

		log( "section");

		//log(l.name);

		for(o=0;o <=l.phrase.size(); o++);
		{
//not close to working yet
log( "--key");
			//log(l.phrase.at(o).c_str()  );
		}
		
	}

}

the INI file

[gotkill]
word1=You Killed

[headshot]
word1=head
word2=helmet
word3=neck

printing the feedback from the sections and keys works fine...i get my INI from each section and key. so i know the data is there...just not filling the vectors

so my question is, it keeps crashing as soon as i try to access the .at...i have no idea how to set this up correctly?

for(i =0; i <= elgbotsections.size(); i++);

You have a rogue semicolon here that should be removed, it's causing the loop to run to completion without doing anything, then when you try to access the vector, i is out of bounds. Also, it should be i < elgbotsections.size() . You presently have an off-by-one error.

Thank You very very much Narue. You beautiful beautiful person!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.