Sign in to follow this  
jaoassy

Tiled Map file import

Recommended Posts

jaoassy    100
hello guys,

i have a simple c++ problem, i guess, i made a tiled map, pretty simple one but i want to make it a little bit more dynamic, using external files as a TXT for the details of a single map instead of writing it in the code source.

i do use int numbers do define the type of each tile:

tiles[x][y] = { 1,1,1,
0,0,0
0,1,0. };

something like that.

now using <fsteam> and importing the same 9 numbers from a map.txt file has been a really annoying thing because i don't know how to READ the file and storing the data into this array:

int tiles[x][y];

when i do:

ifstream myfile;

myfile.open("map.txt");

for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
getline(myfile,tiles[i][j]);

}
}

i get an error that says that i can't convert a STRING into INT.


can someone please show me a way to solve this?

thank you very much,
respectfully, jao.

Share this post


Link to post
Share on other sites
bluehailex    154
Instead of:

[font="Courier New"][code]getline(myfile,tiles[i][j]);[/code][font="Arial"]

you should use:

[code] myfile >> tiles[i][j];[/code]


Edit: The numbers in the text file should be separated by a space or a new line.
[/font][/font]

Share this post


Link to post
Share on other sites
jaoassy    100
[quote name='bluehailex' timestamp='1307648493' post='4821454']
Instead of:

[font="Courier New"][code]getline(myfile,tiles[i][j]);[/code][font="Arial"]

you should use:

[code] myfile >> tiles[i][j];[/code]


Edit: The numbers in the text file should be separated by a space or a new line.
[/font][/font]
[/quote]

ty, it worked very well :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this