Jump to content
  • Advertisement
Sign in to follow this  
Kaberdock

Read from a file

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

Hello,

 

I'm trying to read a some int values from a file but I'm getting wrong values. Here is my code:

if(bg.open(f,"r")>=0){
			
			bg.readLine(line);
			width = parseInt(line);
			bg.readLine(line);
			height = parseInt(line);
			
			
			for(int i = 0; i < height; i++){

				background.insertLast(array<int>(width));
				for(int j = 0; j < width; j++){
					int num;
					uint num2 = 32;
					num = bg.readInt(8);
					//background[i][j] = i;
					print(num2 + " " + num + "\n");
				}
			}
			bg.close();
		}else{
			print("Não foi possível abrir o arquivo.");
		}

Share this post


Link to post
Share on other sites
Advertisement

Is the file in binary format or text format?

 

readLine is meant to be used for files in text format, and readInt for files in binary format. You most likely don't want to use both for the same file, unless the file is mixing text and binary formats.

 

readInt(8) will read an integer number stored in 8 bytes from the file and return it as an int64.

 

You may also want to check the byte-order of the file, you can tell the file object which order to use with the member mostSignificantByteFirst.

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!