| | |
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
Views: 1015 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






