I am very new to programming and would like to append information to a file (not write over existing text)
I am using Microsoft visual c++ and here is my write to file code
(writes all the information over existing text)
#include<iostream.h>
#include<fstream.h>
void main()
{
//declare variables
char firstname[10];//allow upto 10 characters long ?
char surname[10];
char age[10];
char gender[10];
//get input from user
cout<<"enter your christian name : ";
cin>>firstname;//set firstname to name entered by user
cout<<"enter your surname : ";
cin>>surname;//set surname to name entered by user
cout<<"enter your age : ";
cin>>age;//set age to input entered from user
cout<<"male or femele ? ";
cin>>gender;//set gender to inputfrom user
//setup new output stream (give it a name)
ofstream outfile;
//target it to a text file
//then open it ready for data transfer
outfile.open("C:\\outtest.txt");
//send data
outfile<<surname<<endl;
outfile<<firstname<<endl;
outfile<<age<<endl;
outfile<<gender<<endl;
//this just appended the text one after the other
//so how do I append all the text to the end of a file?
cout<<endl<<"file written\n";
}