I did not redesign my functions yet. I just want to solve my problem first. What i want to do is in the vector array when it sees -1 understand that a new line is beginning.
My input file dfa.txt is:
0 0 1 a -1
1 0 3 a 2 b -1
-1
Code:
#include <iostream>
#include "graph.h"
#include <fstream> // for ifstream
#include <string>
using namespace std;
#include "tvector.h"
#include "stdlib.h"
template <class T>
void PutInputToArray(ifstream &dfa,tvector<T> &v)
{
T word;
while(dfa >> word)
{
if(word == "-1")
{
cout<<"hey"<<endl;
}
v.push_back(word);
}
}
void GetIntVal(string &strConvert, int &i) {
i = atoi(strConvert.c_str());
}
int main() {
Graph myGraph;
tvector<string> v;
ifstream dfa;
string file="dfa.txt";
int NumberofStatesInt;
int j=0;
dfa.open(file.c_str());
PutInputToArray(dfa,v);
string NumberofStates = v[0];
GetIntVal(NumberofStates,NumberofStatesInt);
for(j; j< NumberofStatesInt; j++)
{
myGraph.AddVertex(j);
}
int k = 2;
string first = v[2];
string second = v[4];
string second2 = v[6];
int firstint, secondint;
GetIntVal(first,firstint);
GetIntVal(second,secondint);
myGraph.AddEdge(firstint,secondint);
return 0;
}