Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitcb2b000a599570542de4d6ab59a1b78900ce0463 (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-03-10 01:05:14 +0200
Committer
 GitHub <noreply@github.com>
2022-03-10 01:05:14 +0200
Files1500509ab6935ace319b6eed4ccdc3e76ccdf0e6
Object-oriented_programming_FMI-cb2b000a599570542de4d6ab59a1b78900ce0463.tar
Object-oriented_programming_FMI-cb2b000a599570542de4d6ab59a1b78900ce0463.tar.gz
Object-oriented_programming_FMI-cb2b000a599570542de4d6ab59a1b78900ce0463.zip
Parent587e99d4c77331e6176d7bfc286782bfcc993813 (diff)
Update students_staticName_to_binary.cpp
1 files changed, 14 insertions, 0 deletions
-rw-r--r--Sem. 03/students_staticName_to_binary.cpp14
diff --git a/Sem. 03/students_staticName_to_binary.cpp b/Sem. 03/students_staticName_to_binary.cpp
index 1047321..5c9c77d 100644
--- a/Sem. 03/students_staticName_to_binary.cpp
+++ b/Sem. 03/students_staticName_to_binary.cpp
@@ -22,12 +22,26 @@ int main()
ofstream file("student.dat", ios::binary);
+ if (!file.open())
+ {
+ cout << "Error while writing to binary file!" << endl;
+ delete[] s1.name, s2.name;
+ return -1;
+ }
+
file.write((const char*)&st, sizeof(st)); //since the data is grouped in the struct, we can save it like this.
}
{ //read
Student st;
ifstream file("student.dat", ios::binary);
+
+ if (!file.open())
+ {
+ cout << "Error while reading from binary file!" << endl;
+ delete[] s1.name, s2.name;
+ return -1;
+ }
file.read((char*)&st, sizeof(st));