SFML community forums

Help => General => Topic started by: Fierce_Dutch on December 02, 2010, 03:32:38 am

Title: Vector Not Allocating
Post by: Fierce_Dutch on December 02, 2010, 03:32:38 am
Can someone hlep me with this?

Code: [Select]
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main()
{

vector <int> tiletype;
int itemp;
char ctemp;
bool btemp;
vector <bool> solid;

ifstream filein;
filein.open("Test.map");
int i = 0;
while(filein.eof())
{
filein >> itemp;
filein >> ctemp;
filein >> btemp;
tiletype.push_back(itemp);
solid.push_back(btemp);
}

cout << tiletype[0];
cin.get();

}
Title: Vector Not Allocating
Post by: Drektar on December 02, 2010, 03:55:07 am
Hi,

I think this will be better :
Code: [Select]
while( ! filein.eof() )  
Title: Vector Not Allocating
Post by: Fierce_Dutch on December 02, 2010, 05:47:19 am
Quote from: "Drektar"
Hi,

I think this will be better :
Code: [Select]
while( ! filein.eof() )  


Oh i feel so stupid. Been trying so many things with the varibales and all it was, was that. Oop's what a stupid mistake!
Title: Vector Not Allocating
Post by: Laurent on December 02, 2010, 08:07:14 am
This is not correct. eof() should only be used after you couldn't read from the stream, to know if it was caused by the end of file.

The correct version would be:
Code: [Select]
while(filein >> itemp >> ctemp >> btemp)
{
   tiletype.push_back(itemp);
   solid.push_back(btemp);
}


By the way, next time you post for a problem, don't forget to give us information about the problem (what errors do you get, where, what happens, what you tried, ...). "Can someone hlep me with this?" is definitely not enough.