Im having trouble using
getline(fin, temp.name);
Heres the code:
////This is the maps.txt file contents
Number of Tilesets=2
Name=johnny
Width=32
Height=64
TileCount=30
Bitmap=Johnny.bmp
Name=Poops
Width=11
Height=34
TileCount=12
Bitmap=poopydoopy.bmp
//This is the source code
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void main()
{
struct TileSet
{
string name;
int width;
int height;
int tcount;
string gfx;
};
//TileSet green;
vector <TileSet> tilesets;
ifstream in;
in.open("maps.txt");
if (in.fail() || !in.is_open())
{
cerr << "no data/File does not exist.";
exit(0);
}
int nts = 0, nmaps = 0;
int i = 0;
while (1)
{
if (in.get() == '=')
{
in >> nts;
cout << "nts: " << nts << endl;
break;
}
}
while (!in.eof())
{
TileSet temp;
if (in.get() == '=')
//cout << in.get();
{
if (nts > 0)
{
++i;
switch(i)
{
case 1:
getline(in, temp.name);
break;
case 2:
in >> temp.width;
break;
case 3:
in >> temp.height;
break;
case 4:
in >> temp.tcount;
break;
case 5:
getline(in, temp.gfx);
--nts;
i = 0;
tilesets.push_back(temp);
break;
default:
cout << "Unknown\n";
}
}
}
}
for (int i = 0; i < tilesets.size(); ++i)
{
cout << "Name: " << tilesets.name << "\nWidth: " << tilesets.width << "\nHeight: " << tilesets.height;
cout << "\nTCount: " << tilesets.tcount << "\nBitmap: " << tilesets.gfx << endl;
}
//cout << (char)87;
in.close();
}
it all seems to work except
case 1:
getline(in, temp.name);
is capturing nothing. i had it working before but i cant seem to find out why its no longer working, especially when case 5 is.
anyone know whats going on?
Edit by Fruny - Added code tags