Read two files but in two ways and the point where they entry can terminate with '#'

How can I read the two files and how will the entry be terminated with '#'?
I don't know what I'm tried for at this point.

//***********************************************************
// Function Name: GetGraph
// Purpose: get a file that has a graph representing as adjacency list
// Functions Called: AddVertex, AddUniEdge, AddBiDirEdge
//************************************************************
template<class V, class W>
void Graph<V, W>::GetGraph()
{
edgeRep<V, W> G1;
vertex<V, W> dist;
ifstream input, input2;
string line;
input.open("graphs2.txt");
while (!input.eof())
{
input >> line;
AddVertex(dist.name);
while (input >> line != '#')
{
input >> line;
AddUniEdge(G1.name, G1.weight);
}
}

input.close();
input2.open("graph3.txt");

while (!input.eof())
{
input >> line;
AddVertex(dist.name);
while (input >> line != '#')
{
input >> line;
AddBiDirEdge(dist.name, G1.name, G1.weight);
}
}
input2.close();
}
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
template<class V, class W>
void add_vertex(string filename, vertex<V,W>& dist, edgeRep<V,W>& G1, bool bi)
{
    ifstream input(filename);
    string line;
    while (input >> line)
    {
        // presumably the name is extracted from the line?

        AddVertex(dist.name);

        while (input >> line && line != "#")
        {
            // presumably some info is extracted from the line.

            if (bi)
                AddBiDirEdge(dist.name, G1.name, G1.weight);
            else
                AddUniEdge(G1.name, G1.weight);
        }
    }
}

template<class V, class W>
void Graph<V,W>::GetGraph()
{
    edgeRep<V,W> G1;
    vertex<V,W> dist;
    add_vertices("graph2.txt", dist, G1, false);
    add_vertices("graph3.txt", dist, G1, true);

    // ???
}

Last edited on
What does it say on the code?
I edit some of yours but... it's almost.
There are a couple of lines that have the same error:

 
Error	C2677: binary '>>': no global operator found which takes type 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (or there is no acceptable conversion)


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
//***********************************************************
// Function Name: add_Vertices
// Purpose: Adds vertices by reading files and storing in either directional or bidirectional graph.
// Parameters: string filename, vertex<V, W>& dist, edgeRep<V, W>& G1, bool bi
// Functions Called: AddVertex, AddUniEdge, AddBiDirEdge
//************************************************************
template<class V, class W>
void Graph<V,W>::AddVertices(string filename, vertex<V, W>& dist, edgeRep<V, W>& G1, bool bi)
{
	ifstream input(filename);
    string line;
    while (!input.eof())
    {
		input >> line;
        AddVertex(dist.name);

		input >> line;
        while (line != "#")
        {
            if (bi)
                AddBiDirEdge(dist.name, G1.name, G1.weight);
            else
                AddUniEdge(G1.name, G1.weight);
        }
    }
}

//***********************************************************
// Function Name: GetGraph
// Purpose: get a file that has a graph representing as adjacency list
// Functions Called: AddVertices
//************************************************************
template<class V, class W>
void Graph<V, W>::GetGraph()
{
	edgeRep<V, W> G1;
	vertex<V, W> dist;
	AddVertices("graph2.txt", dist, G1, false);
	AddVertices("graph3.txt", dist, G1, true);
}
Topic archived. No new replies allowed.