Jump to content
  • Advertisement
Sign in to follow this  

ifstream help....parsing a .x file

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

		int totalfaces;
		int totalindices;
		inFile >> totalfaces;
		totalindices = totalfaces * 3;
		data.SetIndexCountForObject( objectcount, totalindices );
		inFile >> str; // reads in a semicolon
		for ( int indexcount = 0; indexcount < totalindices; indexcount+=3 )
			char ch;
			int index, temp;
			inFile >> temp; // 3 indices per face, reads in the "3"
			inFile >> ch; // reads in a semicolon
            inFile >> index;
			data.SetIndex( objectcount, indexcount, index );
			inFile >> ch; // reads in a comma
            inFile >> index;
			data.SetIndex( objectcount, indexcount + 1, index );
			inFile >> ch; // reads in comma
            inFile >> index;
			data.SetIndex( objectcount, indexcount + 2, index );
			inFile >> ch; // reads in a semicolon
			inFile >> ch; // reads in a comma

this small cpp chunk is reading the indices from a .x file. this part, specifically:

those are the indices in an x file...anyways, im having a problem at the first inFile >> index statement. when index is declared it is some arbitrary number, lets say 1241528, then the inFile statement is hit and index does not change. This code worked on my previous machine but not my new one. Any advice? ideas? could the functionality/output of the streams differ on different implementations? any help would be appreciated.

Share this post

Link to post
Share on other sites
The comma is being interpreted as part of the integer when it's trying to read it in. This is a locale problem I believe. Look into locales and also you can use the stream state to see if an operation will fail. inFile.fail() will return true if it couldn't read the integer. If you're lazy though you could just do a find and replace to replace all of the commas with semicolons.

Here's how you can remove the ',' grouping (which is the default, but maybe not on your old system) when reading in integers:

class NoSep_Punct : public std::numpunct<char> {
explicit NoSep_Punct(size_t r=0) : std::numpunct<char>(r) { }
char do_thousands_sep() const { return NULL; }

// Then later after you define your ifstream

locale loc(locale(), new NoSep_Punct);

[Edited by - Absolution on October 5, 2006 3:22:05 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!