Advertisement

Read from a file

Started by March 31, 2014 05:01 PM
1 comment, last by Kaberdock 10 years, 7 months ago

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.");
		}

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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Thanks a lot @Andreas Jonsson

This topic is closed to new replies.

Advertisement