Home Forums C Programming Some problems in C++ Re: Re: Some problems in C++

#3511
GWILouisaxwzkla
Participant

for the write function I would do something like ( I don’t think I would have the console prompt inside the function , but if this is what you want ):



void write ()
{

char choice;
cout << "do you want to input data to file ( y or n )" << endl;
cin >> choice;
cin.get(); //get newline
while ( choice != 'y' && choice != 'n' )
{
cout << "bad choice!" << endl;
cout << "do you want to input data to file ( y or n )" << endl;
cin >> choice;
cin.get(); //get newline
}

if ( choice == 'y' )
{
char inputText [ MAX_NAME ];
cout << "enter input text: " << endl;
cin.getline ( inputText , MAX_NAME , 'n' );

ofstream outputFile;
//PUT YOUR DATA FILE NAME HERE!
outputFile.open ( "c:\programs\help\data3.txt" , ios::app );
outputFile << inputText << endl;
outputFile.close();

}

}