how to fix ": Access violation reading location 0xDDDDDDDD." exception

-1

I am writing a function that will read information from a text file and use that information to fill a graph and return it. I have the reading from the graph part figured out, but when I try to return it I get

"Exception thrown at 0x013D0EDD in JohnStipich10AssignmentTen.exe: 0xC0000005: Access violation reading location 0xDDDDDDDD."

the function must return a bool (as per my assignment) -> "bool read(string filename)"

I'm wondering if there's a way that I can return my filled graph like this?

the assignment is : Design a format for storing graphs in files. This will store your graph into a file with the following requirements:

The first line will contain the number of Vertices.
The second line will have a ā€˜Uā€™ or a ā€˜Dā€™ to tell the system if it is Undirected or Directed.
The rest of the lines will be here for each of the edges.  Each edge will contain three pieces of information:
    An integer containing the first Vertex
    An integer containing the second Vertex
    An integer containing the weight

You will need to wright two functions for your graph, read and write.

bool read(string filename);
bool wright(string filename);

The file must be human readable (use a txt file please).

Here is a sample input file.

Input.txt

6 # Number of vertices U # Undirected graph 0 4 9 # List of Edges 0 2 7 2 3 1 2 1 5 2 5 2 .

bool Graph::read(string filename) {
    ifstream file;
    string test;
    temp = new Graph;


    file.open(filename);

    if (!file.eof()) {
        getline(file, test);
        stringstream convert(test);
        int y;
        convert >> y;
        cout << "\nReading " << y;// delete later
        for (int i = 0; i < y; i++)
            temp->addVertex();


        getline(file, test);
        cout << "\nReading " << test;// delete later
        if (test == "U")
            temp->isDirected = false;
        else
            temp->isDirected = true;

        int vOne = NULL, vTwo = NULL, wei = NULL;

        while (!file.eof()) {
            getline(file, test);
            cout << "\nReading " << test;
            string delimiter = " ";

            size_t pos = 0;

            string vect1;
            string vect2;
            string weight;
            stringstream v1(test);


            //int vOne = 0, vTwo = 0, wei = 0;

            pos = test.find(delimiter);
            vect1 = test.substr(0, pos);
            cout << vect1;
            v1 >> vOne;
            cout << "\nReading " << vOne;// delete later
            test.erase(0, pos + delimiter.length());

            stringstream v2(test);

            pos = test.find(delimiter);
            vect2 = test.substr(0, pos);
            v2 >> vTwo;
            cout << "\nReading " << vTwo;//delete later
            test.erase(0, pos + delimiter.length());

            stringstream w(test);

            pos = test.find(delimiter);
            weight = test.substr(0, pos);
            w >> wei;
            cout << "\nReading " << wei;
            test.erase(0, pos + delimiter.length());
            if (vOne != vTwo) {
                temp->addEdge(vOne, vTwo, wei);
            }

        }


        temp->print();

    }



    file.close();
    //cout << test;


    return true;


}


Graph Graph::returnGraph() {
    cout << "\nreturning Graph";

    temp->print();

    return *temp;
}


I have an instance of Graph in my graph.cpp/Graph.h called temp

class Graph
{
private:
    int maxSize;        //Maximum Size
    int size;           // Current size
    int edges;          // number of edges
    int **graph;        // Adjacency Matrix
    bool isDirected;    // Is this a directed or undirected graph

    Graph *temp;

I want the function/functions to return a filled graph so that my Driver.cpp can use it, but when I try to run it it throws an exception reading :

"Exception thrown at 0x013D0EDD in JohnStipich10AssignmentTen.exe: 0xC0000005: Access violation reading location 0xDDDDDDDD.

c++
asked on Stack Overflow Apr 21, 2019 by mstipich

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0