File I/O

I am writing a header file dealing with class I have named account. I have to go over a list on accounts and put it into a file as well as create a list of accounts in a file. I know they both have to do with an input and output file. Write a function that prints an array of accounts to a file; The output file must have the following format:
N
accountNum1 ssn1 name1 balance1
accountNum2 ssn2 name2 balance2
...
...
accountNumN ssnN nameN balanceN

I am not sure how to write this in my header file and I am very stumped. I have as follows:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  
void accounts2file(std::string ofname, Account accounts[], int numaccounts){
//array of accounts to file

	std::string filename = "outfile.txt";
	std::ofstream outFile;
  
	outFile.open(filename.c_str());
	if (outFile.fail()){
		std::cout<< "The File was not opened" << std::endl;
		exit(1);
	}
	
	outFile << numaccounts << std::endl;
			
  outFile.close();
  
  }
If you have a data thats structured then why are u using a text file.Rry opening ur file in binary mode.
try these links. they'll worth reading

http://courses.cs.vt.edu/cs2604/fall01/binio.html

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.