Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KousukeSuzuki25555/0803a179580d3cb8baee3a2f66f3c4db to your computer and use it in GitHub Desktop.
Save KousukeSuzuki25555/0803a179580d3cb8baee3a2f66f3c4db to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct TempStruct { //お試し用構造体
char temp2[23] = "構造体の中のchar型配列";
int value2 = 3;
};
int main(void) {
//保存する変数
char temp[] = "char型の配列";
const char* temp2 = "char型のポインタ";
int value = 0;
int* pValue = new int();
*pValue = 1;
TempStruct tempStruct;
ofstream saveFile; //ファイル変数
string fileName = "saveData.bin"; //保存されるファイルの名前
//保存を行う部分
saveFile.open(fileName, ios::binary); //第一引数:ファイル名 第二引数:モード
saveFile << temp << endl; //char型の配列
saveFile << *temp2 << endl; //char型のポインタの値
saveFile << temp2 << endl; //char型のポインタ変数
saveFile << value << endl; //int型の変数
saveFile << *pValue << endl; //int型のポインタの値
//saveFile << tempStruct << endl; //構造体の保存(出来ない?)
saveFile.close();
//メモリの開放
delete pValue;
return 0;
}
.gist .gist-data{
max-height:400px!important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment