Home › Forums › C Programming › Some problems in C++ › Re: Re: Some problems in C++
January 24, 2009 at 9:11 pm
#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 ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <br /> <br /> void write ()<br /> {<br /> <br /> char choice;<br /> cout << "do you want to input data to file ( y or n )" << endl;<br /> cin >> choice;<br /> cin.get(); //get newline<br /> while ( choice != 'y' && choice != 'n' )<br /> {<br /> cout << "bad choice!" << endl;<br /> cout << "do you want to input data to file ( y or n )" << endl;<br /> cin >> choice;<br /> cin.get(); //get newline<br /> }<br /> <br /> if ( choice == 'y' )<br /> {<br /> char inputText [ MAX_NAME ];<br /> cout << "enter input text: " << endl;<br /> cin.getline ( inputText , MAX_NAME , 'n' );<br /> <br /> ofstream outputFile;<br /> //PUT YOUR DATA FILE NAME HERE!<br /> outputFile.open ( "c:\programs\help\data3.txt" , ios::app );<br /> outputFile << inputText << endl;<br /> outputFile.close();<br /> <br /> }<br /> <br /> }<br /> |