Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- struct test {
- int integer;
- float floating;
- };
- void save(const char* path, const test& source) {
- fstream file(path, ios::out | ios::binary);
- if (file.is_open()) {
- file.write((char*)&source, sizeof(source));
- file.close();
- }
- }
- void load(const char* path, test& destination) {
- fstream file(path, ios::in | ios::binary);
- if (file.is_open()) {
- file.read((char*)&destination, sizeof(destination));
- file.close();
- }
- }
- int main() {
- test testData;
- testData.integer = 12;
- testData.floating = 1.4f;
- save("test.bin", testData);
- test loaded;
- load("test.bin", loaded);
- cout << "Int: " << loaded.integer << " Float: " << loaded.floating << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement