Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Filling array from a file

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

Ok. I have searched through the forums until my eyes began to hurt. I am saving my array (for a tile engine) to file, thats ok. I am then reloading, this also is ok. But... I want to be able to specify the size of the array in the file, again saving is not a problem, but when it comes to reload i am having problems. fin>>Size; int const MAPSIZE = Size; char map[MAPSIZE][MAPSIZE]; ... It doesn''t work due to the const. If anyone could give any advise it would be much appriciated, thanks.

Share this post

Link to post
Share on other sites
Yes, and when allocating memory with new[], don't forget to delete[] it! Like this:


char* map = new char[Size * Size];

//use the map
map[6 + 3 * Size] = 'a'; //access coordinate (6, 3)

delete[] map;

Personally I'd recommend using Boost.MultiArray or just std::vector, but beginners usually tend to ignore such suggestions so I won't tell more unless you ask.

[edited by - civguy on February 8, 2003 7:43:05 AM]

Share this post

Link to post
Share on other sites

  • 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!