Save the file in an array of values

There is a class for creating an array and class that stores the values of this array in the file. It saves only the address, but I need value. I can not find my mistake

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  class Temp;
class Array
{
    int*m_mas;
    int m_size;
    Temp*m_temp;
public:
    Array(int size);
    void create();
    void show();
    void setTemp(Temp*temp);
    void save();
    ~Array();
};
 
Array::Array( int size):m_size(size),m_mas(new int[m_size])
{
}
 
void Array::create()
{
    for (int i = 0; i < m_size; ++i)
        m_mas[i] = rand() % 20;
    
}
 
void Array::show()
{
    for (int i = 0; i < m_size; ++i)
    cout << m_mas[i] << " ";
}
 
void Array::setTemp(Temp * temp)
{
    m_temp = temp;
}
 
void Array::save()
{
    m_temp->write("file.txt", m_mas, m_size);
}
 
 
Array::~Array()
{
}
 
class Temp
{
public:
    Temp();
    int write(const char*name, const void*Array, int size);
    ~Temp();
};
 
#include "Temp.h"
#include<iostream>
#include<fstream>
using namespace std;
 
 
Temp::Temp()
{
}
 
int Temp::write(const char * name, const void * Array, int size)
{
    name = "file.txt";
    ofstream fout;
    fout.open(name, ios_base::out | ios_base::ate);
    if (!fout.is_open()) {
        cerr << "Error! File is not open\n";
        return -1;
    }
 
    int*Arr = new int[size];
    Array = Arr;
    for (int i = 0; i < size; ++i)             //something is wrong
    {
 
        fout << Arr[i];                 // it is necessary that the value story goes          
    }
   fout.close();
    return Arr[size];



    delete[]Arr;
}
 
 
Temp::~Temp()
{
}
 
auto main(int argc, char*argv[])->int
{
    Array ob(8);
    ob.create();
    ob.show();
    ob.save();
    
}
Topic archived. No new replies allowed.