How to read a random number array to an output file

I need help with reading an array with random numbers into an output file.This is not my full code but everything compiles correctly with no errors, the problem is that i output a certain set of random numbers to the debuggin screen but when i read this set of numbers to the file, i dont obtain the same set of numbers. I obtain back the right dimensions, and the same amount of numbers but theyre not the same numbers... I need help with this for this is not the last step of the program, Its due tomorrow.

Code:
ofstream yourfile ;
	string filename ;
	
	cout << "input a filename : \t" ;
	cin >> filename ;
	yourfile.open( filename.c_str() )	;
	
	yourfile << inputted_row << " "  << inputted_column << endl ;
    
	int *matrix = new int[inputted_row] ;
	matrix = new int [inputted_column] ;
	for( column = 0 ; column < inputted_row ; ++column )			
		{															
			for( row = 0 ; row < inputted_column ; ++row )			
				{	 
					random_number = rand()%100 ;					
					yourfile << random_number << "\t"  ;
					
				}
	
		}
	delete [] matrix ;
	
	if (!yourfile)
	{
		cout << " Error. Can not open output file." << filename ;
		cout << "\n Exiting program, Goodbye" ;
		exit(1) ;
	};
	
	cout << " Just sent a message to the file " ;
	yourfile.close() ;

	
	system("pause") ;
	return 0 ;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
int *matrix = new int[inputted_row] ;
	matrix = new int [inputted_column] ;
	for( column = 0 ; column < inputted_row ; ++column )			
		{															
			for( row = 0 ; row < inputted_column ; ++row )			
				{	 
					random_number = rand()%100 ;					
					yourfile << random_number << "\t"  ;
					
				}
	
		}
	delete [] matrix ;


1) This a memory leak since the second time you use new, you are removing the pointer to the first set of memory.
2) You never actually use matrix.
3) You never load anything from the file, you just save it.
So how would i have to set up this loop?
Your loop looks fine, it's just that you aren't ever using matrix.
Topic archived. No new replies allowed.