diff options
Create static_struct_binary.cpp
1 files changed, 31 insertions, 0 deletions
| -rw-r--r-- | Sem. 03/static_struct_binary.cpp | 31 |
diff --git a/Sem. 03/static_struct_binary.cpp b/Sem. 03/static_struct_binary.cpp new file mode 100644 index 0000000..6ee16de --- /dev/null +++ b/Sem. 03/static_struct_binary.cpp @@ -0,0 +1,31 @@ +#include <iostream> +#include <fstream> +#pragma warning(disable:4996) +using namespace std; + + +struct Test +{ + bool b; + int x; +}; + +int main() +{ + + { //write + Test t = { true, 45 }; + ofstream file("testObj.bat", ios::binary); + + file.write((char*)&t, sizeof(t)); + } + + { //read + Test t; + ifstream file("testObj.bat", ios::binary); + + file.read((char*)&t, sizeof(t)); + std::cout << t.b << " " << t.x << std::endl; + } + +} |
