@GatorGirl/

AromaticUnripeKey-Writing Binary File

C++11

No description

fork
loading
Files
  • main.cpp
  • memory.bin
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <vector>
using namespace std;

int main() 
{
  time_t now = time(0);
  char* dt = ctime(&now);
  cout << dt << endl;

  fstream file("memory.bin", ios_base::out | ios_base::binary);
  if (file.is_open())
  {
    int numOfPlayers = 1;
    char* name = "Alexis";
    int nameL = 7;
    int password = 123456;
    vector<char*> heroNames;
    heroNames.push_back("The One and Only");
    int nameLength = 17;
    int heroNamesL = heroNames.size();
    vector<char*> times;
    int timesL = times.size();
    time_t now = time(0);
    char* dt = ctime(&now);
    times.push_back(dt);
    int TimeCharL = 25;

    file.write((char*)&numOfPlayers, sizeof(numOfPlayers));

    file.write((char*)&nameL, sizeof(nameL));
    file.write(name, sizeof(nameL));
    file.write((char*)&password, sizeof(password));

    file.write((char*)&heroNamesL, sizeof(heroNamesL));
    file.write((char*)&nameLength, sizeof(nameLength));
    file.write((char*)&heroNames[0], sizeof(nameLength));

    file.write((char*)&timesL, sizeof(timesL));
    file.write((char*)&TimeCharL, sizeof(TimeCharL));
    file.write((char*)&times[0], sizeof(TimeCharL));
    
    file.close();
  }
}