Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / students_staticName_to_binary.cpp
diff options
context:
space:
mode:
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;
+}