c++ - Take input from keyboard and edit existing text file -
i have been having problems code , lost.
need user use console read text file , update new records.
example doing football type project. have 9 players in football team , want able add new players console, when added start last entry in file , add new 1 there 10 total players if new player added.
void addfootballplayer(football footballplayer[], int *f); { string forename, surname; int defence, strike, midfield; ofstream fout; fout.open("footballteam.txt"); cout << "enter first name "; cin >> forename; cout << endl; cout << "enter surname "; cin >> surname; cout << endl; cout << "enter strike power "; cin >> strike; cout << "enter defence power "; cin >> defence; cout << "enter midfield power "; cin >> midfield;
you need write file using file stream have defined once have taken inputs , can using fout
follows. additionally, there different modes in open file writing it, can go through here.
fout.open("footballteam.txt"); cout << "enter first name "; cin >> forename; fout << forename << " "; cout << endl; cout << "enter surname "; cin >> surname; fout << surname << " "; cout << endl; cout << "enter strike power "; cin >> strike; fout << strike << " "; cout << "enter defence power "; cin >> defence; fout << defence << " "; cout << "enter midfield power "; cin >> midfield; fout << midfield << "\n";
open , take @ footballteam.txt
find above snippet does.
hope helps.
Comments
Post a Comment