Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Vector Not Allocating  (Read 1788 times)

0 Members and 1 Guest are viewing this topic.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Vector Not Allocating
« 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();

}

Drektar

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Vector Not Allocating
« Reply #1 on: December 02, 2010, 03:55:07 am »
Hi,

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

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Vector Not Allocating
« Reply #2 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Vector Not Allocating
« Reply #3 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.
Laurent Gomila - SFML developer