Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib> //needed for atoi for linux box dev, not automatically put in global scope
- #include <fstream>
- #include <string>
- #include <list>
- using namespace std;
- string* parseLine(string*,string,char);
- string* parseLine(string* ary,string line,char delim)
- {
- unsigned int i = 0 ;
- unsigned int beg = 0;
- unsigned int end = 0;
- for(; end < line.length(); end++)
- {
- if(line[end] == delim)
- {
- ary[i++] = line.substr(beg,end-beg);
- end += 1;
- beg = end;
- }
- if(line.length()-1 == end)
- ary[i++] = line.substr(beg,end-beg+1);
- }
- return ary;
- }
- int main(){
- list<string*> rVert;
- list<string*> tVert;
- int counter = 0;
- int total = 0;
- string* infoVert;
- string* temp;
- ifstream data;
- data.open("disneyland.txt");
- string output;
- string total_nodes = "";
- string* temp2;
- if (data.is_open()) {
- while (!data.eof()) {
- if (counter == 0) //grabbing the total amount of vertcies
- {
- getline(data,output);
- total = atoi(output.c_str());
- }else{ // now parsing line into an array then pushing it into the remaining list.
- infoVert = new string[4];
- getline(data,output);
- temp = parseLine(infoVert,output,' ');
- cout << "id: " << temp[0] << " ,x: " << temp[1] << " ,y: " << temp[2] << " ,name: " << temp[3] << endl;
- rVert.push_front(temp);
- delete [] infoVert;
- }
- counter++;
- }
- }
- //---------------------
- //cleaning up the mess.
- data.close();
- //---------------------
- while(!rVert.empty())
- {
- temp2 = rVert.front();
- cout << "id: " << temp2[0] << " ,x: " << temp2[1] << " ,y: " << temp2[2] << " ,name: " << temp2[3] << endl;
- rVert.pop_front();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement