| | |
appending the end of a file
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
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: 1027 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






