| | |
Homework help...How do I save name into another file??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
How do I make C++ save the names entered by the user into another file on the computer???
#include<iostream> #include<cstdlib> #include<iomanip> #include<string> #include<fstream> #include<vector> using namespace std; struct players { string fname; string lname; int atbats; int runs; int hits; int doubles; int triples; int hrs; int rbi; int sos; double avg; }; int main() { void bubblesort2(players team[]); string ifile="top100off.txt", ofile="top60def.txt", name; players team[100]; int i, c; ifstream inFile; inFile.open(ifile.c_str()); if (inFile.fail()) { cout << "The file was not opened." << endl; exit(1); } inFile >> team[0].fname >> team[0].lname >> team[0].atbats >> team[0].runs >> team[0].hits >> team[0].doubles >> team[0].triples >> team[0].hrs >> team[0].rbi >> team[0].sos >> team[0].avg; for(i=1; i<100; i++) { inFile >> team[i].fname >> team[i].lname >> team[i].atbats >> team[i].runs >> team[i].hits >> team[i].doubles >> team[i].triples >> team[i].hrs >> team[i].rbi >> team[i].sos >> team[i].avg; cout << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs << " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs << " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << "\n"; } ofstream outFile; outFile.open(ofile.c_str()); if (outFile.fail()) { cout << "Failed!!!." << endl; } //bubblesort2(team); for (c=1; c<=5; c++) { cout << "Type a last from the offensive player list. " << endl; getline(cin, name); if (islower(name[0])) { name[0]=toupper(name[0]); } for (i=0; i<100; i++) { if (team[i].lname == name) { outFile << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs << " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs << " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << endl; } } } for(i=0; i<100; i++) { outFile << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs << " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs << " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << endl; } outFile.close(); cout << "Closed."; cin.ignore(); return 42; } void bubbleSort2(players team[]) { bool doMore; do { doMore = false; for (int i=0; i<100; i++) { if (team[i].lname > team[i+1].lname) { players temp = team[i]; team[i] = team[i+1]; team[i+1] = temp; doMore = true; } } } while (doMore); }
![]() |
Similar Threads
- Excel Macro Save as with date in file name (Visual Basic 4 / 5 / 6)
- save ARRay elements to a file (C++)
- Interactive text file (C++)
- line up JTextField GUI java & write to file (Java)
- how willl i be able to save a specific record into my database file in ms access (Java)
- Saving a file using C++ (C++)
- adding totals in listboxes (Visual Basic 4 / 5 / 6)
- file input and output (C)
Other Threads in the C++ Forum
- Previous Thread: i need help bad
- Next Thread: C++ in subversion
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






