you may want to look into binary file I/O, and by extension, data structures:
Code:
#include<iostream> //for console I/O
#include<fstream> //for file I/O
#include<cstdlib> //for rand function
#include<ctime> //for time function
struct myBoard //to be saved to and read from a file
{
int layout[20][60]; //your board
};
int main()
{
srand(static_cast<unsigned int>(time(0))); //seed the PRNG
myBoard board; //instantiate the struct
myBoard testboard; //for testing purposes
//open a file for binary writing
std::ofstream ofile("test.in",std::ios::trunc|std::ios::binary);
/*
* You would need to create a level generator - I'm using a simple
* one that just throws a random number into each spot - it would
* be no use to you.
*/
for(register short int x=0;x<20;x++) //loop through the colums
{
for(register short int y=0;y<60;y++) //loop through the rows
{
board.layout[x][y]=rand()%10;
}
}
ofile.write(reinterpret_cast<char*>(&board),sizeof(board)); //write the struct
ofile.close(); //close the file
/*
* now you need to create a program to read the file(s) you just wrote
* again, this code will only show you how to do it - you'll need to
* make some modifications to tailor it to your own uses
*/
//open a file for binary reading
std::ifstream infile("test.in",std::ios::binary);
//read it into a different instance of the same struct (for testing)
infile.read(reinterpret_cast<char*>(&testboard),sizeof(testboard));
for(register short int x=0;x<20;x++) //loop through the colums
{
for(register short int y=0;y<60;y++) //loop through the rows
{
//if the boards match
if(testboard.layout[x][y]==board.layout[x][y])
{
std::cout<<board.layout[x][y];
}
else //if there's a discrepancy between the original
{ //map and the one you just read
std::cerr<<"DATA CORRUPTION DETECTED\n";
break;
}
}
std::cout<<'\n';
}
infile.close(); //close the file
return 0;
}
as you may or may not be able to pick up, structs can hold pretty much any data type (and not just one at a time, either). you can use an integer for the color, a string for the name, etc.