• Advertisement
Sign in to follow this  

Tiled Map file import

This topic is 2446 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 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[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
Advertisement
Instead of:

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

you should use:

myfile >> tiles[j];


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

Instead of:

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

you should use:

myfile >> tiles[j];


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


ty, it worked very well :D

Share this post


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

  • Advertisement