destroying file while using fstream

Hey am having truble finding out way i can run a file once and things work but when i try to run it again. It fails.
My class methods.
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
#include "includes.h"

    clsFILE::clsFILE(string FullFilePath)
    {
        FilePath = FullFilePath;
        cPath = new char[FilePath.length() + 1];
        strcpy( cPath, FilePath.c_str() );

        objFILE.open(cPath, ios_base::binary);
        if ( objFILE.is_open() && objFILE.good() ) // Open File
        {
            MessageBox(NULL, "Opend!.", cPath, MB_OK|MB_ICONINFORMATION);
        } else { // Error Faild to open
            MessageBox(NULL, "Faild To Open File. ", cPath, MB_OK|MB_ICONERROR);
            }
    }

    void clsFILE::AddLineToFile(string NewLine)
    {
        string Line = NewLine;
        cout << "2:File Good Now" << endl; Sleep(200);
        objFILE << Line << endl;
    }

    string clsFILE::ReturnFileBuffer()
    {
        cout << "Retriving File Buffer..." << endl;
        objFILE.seekg(0, std::ios::end);
        size_t size = objFILE.tellg();
        string FILE_Buffer(size, ' ');
        objFILE.seekg(0);
        objFILE.read(&FILE_Buffer[0], size);

        return FILE_Buffer;
    }

    void clsFILE::GetFileLineByLine()
    {
        cout << "Geting Line by Line from File..." << endl;
        objFILE.seekg(0);
        while ( !objFILE.eof() && objFILE.good() && objFILE.is_open() ) {
            string Line;
            getline(objFILE, Line);
            LineByLineVectorFILE.push_back(Line);
            // cout << "Line: " << Line << std::endl;
        }
    }

    string clsFILE::ReturnFILE_Buffer()
    {
        cout << "Returning Found File Buffer..." << endl;
        return FILE_Buffer;
    }

                                    // Pos of string to output
    string clsFILE::ReturnVectorLine(int i)
    {
        cout << "return LineByLineVectorFILE[i]..." << endl;
        return LineByLineVectorFILE[i];
    }
    size_t clsFILE::ReturnLineByLineVecorSize()
    {
        cout << "return LineByLineVectorFILE.size()..." << endl;
        return LineByLineVectorFILE.size();
    }
    void clsFILE::AddLineToVector(string FoundNew)
    {
        cout << "Adding New Line to vector..." << endl;
        LineByLineVectorFILE.push_back( FoundNew );
    }

    void clsFILE::ClearLineByLineVector()
    {
        cout << "LineByLineVectorFILE.clear()..." << endl;
        LineByLineVectorFILE.clear();
        //MessageBox(NULL, "Vector Cleard", "Content Deleted", MB_OK|MB_ICONINFORMATION);
    }

    clsFILE::~clsFILE()
    {
        objFILE.close();
        delete[] cPath;
        cPath = '\0';
    }

Any tips is gretly aprichiated
1
2
delete[] cPath;
cPath = '\0';


What are you doing that for? It will work, but I doubt it will do what you expect it to. Other than that your code seems ok at first glance, although your naming convention (if you have one) seems a bit strange to me.
Last edited on
Topic archived. No new replies allowed.