Jump to content
  • Advertisement
Sign in to follow this  
zalthar

seekg & read

This topic is 5411 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

When I run the check_If_Tga theres no problem, but then after that when I run read_Tga_File it doesn't but anything in m_tgaFileHeader. But if I skip the first function it puts the correct data in m_tgaFileHeader but one byte backwards.
bool CTga::check_If_Tga()	
{
	char Str[17];
	// Go to the TRUEVISION-XFILE start bit. 
	// And put the next 16 bits in str.
	m_file.seekg( -18, ios_base::end );	
	m_file.getline(Str, 17);	

	// If the 16bits are "TRUEVISION-XFILE" then return true.
	if( !strcmp(Str, "TRUEVISION-XFILE"))
		return true;
	else
		return false;
}


void CTga::read_Tga_File()
{
	m_file.seekg( 0, ios_base::beg);
	m_file.read((char*) &m_tgaFileHeader, sizeof(tga_file_header));
}

Share this post


Link to post
Share on other sites
Advertisement
The file is being placed in an error state after the check_If_Tga function runs because of eof. Call m_File.clear() before trying to read again.

Two other things, one, I'm not sure that the parameter is supposed to be negative. I think it might be a positive number when its ios::end. Two, you should use read rather than getline. I'm not too familiar with text mode files but that reads until it reaches a carriage return.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!