FileExample9 (1)
FileExample9 (1)
#include <string>
#include <fstream>
struct student {
char name[NAME_SIZE];
float score;
};
if (fs)
while (true) {
cout << "Creating a structure ..." << endl;
cout << "Name: ";
cin.getline(s.name, NAME_SIZE);
cout << "score: ";
cin >> s.score;
cin.ignore();
if (fs) {
fs.read(reinterpret_cast<char *> (&s), sizeof(s));
while (fs) {
cout << s.name << endl;
cout << s.score << endl;
cout << endl;
fs.seekg(0L, ios::end);
numOfItems = fs.tellg() / sizeof(student);
cout << "Which item do you want to update (0 - " << numOfItems -
1 << "): ";
cin >> item;
fs.close();
}
int main() {
fstream fs;
string filename;
writeFile(fs, filename);
readFile(fs, filename);
updateFile(fs, filename);
readFile(fs, filename);
return 0;
}