Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commite209e6eaf7fdbb147daba4dc54a50fd41cdd3b05 (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-03-09 16:01:45 +0200
Committer
 GitHub <noreply@github.com>
2022-03-09 16:01:45 +0200
Files4488cb35117ba92ac7329d884089db138dfa3aba
Object-oriented_programming_FMI-e209e6eaf7fdbb147daba4dc54a50fd41cdd3b05.tar
Object-oriented_programming_FMI-e209e6eaf7fdbb147daba4dc54a50fd41cdd3b05.tar.gz
Object-oriented_programming_FMI-e209e6eaf7fdbb147daba4dc54a50fd41cdd3b05.zip
Parentf83429a1b366d63d360ff912f98b3ef65da4a5a1 (diff)
Create students_staticName_to_binary.cpp
1 files changed, 37 insertions, 0 deletions
-rw-r--r--Sem. 03/students_staticName_to_binary.cpp37
diff --git a/Sem. 03/students_staticName_to_binary.cpp b/Sem. 03/students_staticName_to_binary.cpp
new file mode 100644
index 0000000..8f84d79
--- /dev/null
+++ b/Sem. 03/students_staticName_to_binary.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <fstream>
+#include <cstring>
+
+using namespace std;
+
+
+struct Student
+{
+ char name[25];
+ int fn;
+ int age;
+};
+
+int main()
+{
+ { //write
+ Student st;
+ strcpy(st.name, "Ivan");
+ st.fn = 1234;
+ st.age = 33;
+
+ ofstream file("student.dat", ios::binary);
+
+ file.write((const char*)&st, sizeof(st));
+ }
+
+ { //read
+ Student st;
+ ifstream file("student.dat", ios::binary);
+
+ file.read((char*)&st, sizeof(st));
+
+ std::cout << st.name << " " << st.fn << " " << st.age << std::endl;
+ }
+ return 0;
+}