| | |
appending the end of a file
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 34
Reputation:
Solved Threads: 0
I'm trying to append the end of the file treatments.txt but am unsure how to use the while loop correctly!! Any suggestions?? I tried boolean with the whiles aswell but can't seem to get it to work either. Like asking do you want to continue adding treatments and if yes set bool to false and exit while statement.
C++ Syntax (Toggle Plain Text)
void enterTreatments( T * treatArray, int numTreatments) { int treatmentNumber = -1; ofstream outfile; outfile.open("treatments.txt"); // while(numTreatments > treatmentNumber) for (int i = 0; i < numTreatments; i++) { cout << "Enter treatment ID" << endl; cin >> treatArray[i].treatmentID; outfile << treatArray[i].treatmentID; cin.get(); cout << "Enter treatment Description" << endl; getline(cin,treatArray[i].treatmentDescription); outfile << treatArray[i].treatmentDescription; cout << "Enter cost for treatment" << endl; cin >> treatArray[i].cost; outfile << treatArray[i].cost; cout << "Enter number of required sessions" << endl; cin >> treatArray[i].noOfRequiredSessions; outfile << treatArray[i].noOfRequiredSessions; treatArray[i].costPerSession = treatArray[i].cost/treatArray[i].noOfRequiredSessions; //cout << "Enter cost per session " << endl; //cin >> treatArray[i].costPerSession; cout << "Cost for each session is = " ; cout << treatArray[i].costPerSession << endl; cin.get(); outfile << treatArray[i].costPerSession; treatmentNumber++; } }
![]() |
Similar Threads
- Writing a Hangman game (C++)
- how to replace characters in a file (C)
- Help with appending text file (VB.NET)
- java object file reading (Java)
- Getting all data from an input and output file (C++)
- hlp me in dis code!! (C++)
- WriteFile() function in printf() freezes (C)
- file save load problems (C++)
- Interpretation of an instructors C++ program... (C++)
Other Threads in the C++ Forum
- Previous Thread: Functions
- Next Thread: I`m new in c++...i need some help!Uganda
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






