I'm doing a practice project to save golf statistics. It will display different data using tables. I wanted to run it through a jar file. But when I exit, obviously all of the data in my arrayList is gone.

Any ways to save the arraylist?

thanks a lot,

-10100

Recommended Answers

All 4 Replies

Also How to load the saved data..

thanks again.

You can load an array list using fstream. This example is used to draw maps.

int **map;
char c;
void draw(int Width,int Height){
	
	for ( int x=0;x<Width;x++)
	{
		for( int y = 0; y < Height; y++)
		{
			
			cout << map[x][y];
		}
		cout<<"\n";
	}
	delete map;	
}
bool Memalloc(int Width,int Height)
{

		map = new int*[Width];

		for( int x=0;x<Width;x++){
	
		map[x] = new int[Height];
		}
		
 
return true;
}
bool draw_map(char* Filename){


	int Width,Height;

	ifstream file;
	file.open(Filename);

	if(!file)return false;

    file >> Width >> Height;///two numbers separated by a white space at the beggining of the file
	Memalloc(Width,Height);

		while(!file.eof()){	
	
			for (int x=0;x<Width;x++){

				for(int y = 0; y <Height; y++){
						
					if(c!=']'){
						file >> map[x][y];//write map
						file.get(c);

					}

				}

			}
		
		}
	


	
	file.close();
	draw(Width,Height);
	return true;
}

I would write the array to a file then load it back in every time the Jar is ran.

this might help more since its java rather then c++ http://www.javapractices.com/topic/TopicAction.do?Id=42

Edit: and after inspecting your code closely and relising it is C++ so ignore my comment unless you need it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.