• [C++]Storing 2d char array to file and load it. How?
    9 replies, posted
How would I store a 2d array in c++ and also load one?
[url]http://www.cplusplus.com/reference/iostream/fstream/[/url] Just make your own binary format that outlines the dimensions of the array then stores it linearly as a series of values.
And what's with all the one question threads lately? The "What do you need help with?" thread is there for a reason
[QUOTE=Jallen;25512474][url]http://www.cplusplus.com/reference/iostream/fstream/[/url] Just make your own binary format that outlines the dimensions of the array then stores it linearly as a series of values.[/QUOTE] Would it not be easier to store say, 4 numbers that are the length of the array, then straight out fprintf it? Or are we going with C++ streams etc?
[QUOTE=Darwin226;25512498]And what's with all the one question threads lately? The "What do you need help with?" thread is there for a reason[/QUOTE] this this and this
-snip- rate box
[QUOTE=Darwin226;25512498]And what's with all the one question threads lately? The "What do you need help with?" thread is there for a reason[/QUOTE] Sorry, didn't see that one :(
[QUOTE=Icedshot;25512579]Would it not be easier to store say, 4 numbers that are the length of the array, then straight out fprintf it? Or are we going with C++ streams etc?[/QUOTE] Well the thread is about C++, so I advised on C++, not C. Also it's not in any way easier to use fprintf. And AFAIK fprintf is used for text, which would be a pretty bad idea to use for this. A binary file would be better. Also I fail to see how you need 4 numbers to signify the length of the array. Doing it my way you only need 2 integers to signify the width and the height. (width)(height)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)etc. Then when parsing you simply read the first 2 ints, make a 2d array of that size and do a for loop with a nested for loop to populate it.
[QUOTE=Jallen;25513397]Well the thread is about C++, so I advised on C++, not C. Also it's not in any way easier to use fprintf. And AFAIK fprintf is used for text, which would be a pretty bad idea to use for this. A binary file would be better. Also I fail to see how you need 4 numbers to signify the length of the array. Doing it my way you only need 2 integers to signify the width and the height. (width)(height)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)(data)etc. Then when parsing you simply read the first 2 ints, make a 2d array of that size and do a for loop with a nested for loop to populate it.[/QUOTE] You're right actually, storing it binary information would make a lot more sense. The thinking behind the 4 numbers was that it would be stored as 4 characters in the file, which would represent a maximum length of the array (so 9999). As a binary file though, you dont need to faff about :3
[QUOTE=efeX;25512595]this this and this[/QUOTE] Hmm I think we should revert to question threads because the what do you need help section doesn't get as much interest as individual threads.
Sorry, you need to Log In to post a reply to this thread.