char data[100] ;


// opening a file in the write mode.
ofstream outfile ;
outfile.open( " Demo2.txt " );
cout << " Writing to the file Demo2.txt" << endl;


cout << " Enter your name : ";
cin.getline(data,100);
// writing the input data into the outfile.
outfile << data << endl;


cout << " Enter your age: ";
cin >> data;
cin.ignore();
// writing the input data into the outfile.
outfile << data << endl;


// closing the opened file.
outfile.close(); //this much works!


// opening a file in read mode.
ifstream infile;
infile.open("Demo2.txt ");
cout << " Reading from the file Demo2.txt " << endl;
infile >> data;


// writing the data
cout << data << endl;


// reading the data from the file
infile >> data;
cout << data << endl;


// closing the opened file.
infile.close();


The first half of this code works. The second half shows the 2nd entry (2x) from the Demo2.txt file and not the name and number in the Demo2.txt file. In the debugger, data shows that the number seems to be overriding the name. A little perplexed here.
maxcy