CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    54

    Reading in input from file

    I have data like this in a text file

    A 2 B F
    B 1 E
    E 0
    F 3 A B E

    The first is the vertex name...so A in the first line
    The second is the # of vertices it is connected to (out-degree)...so 2
    Everything after the integer needs to be added to a linked list...the vertices that A is connected to... B->F will be what the linked list looks like for A.

    Keep in mind the adjacent vertices list isn't fixed...it can be empty as seen for E or it can go to 100...or beyond.

    I have this for reading in the input...I'm using an array of structs...but I'm stuck on the linked list part since it isn't fixed.

    Code:
                    ifstream fin;
    	fin.open("table.txt");
    	
    	int i = 0;
    	while(!fin.eof()){
    		
    		fin >> Gtable[i].name >> Gtable[i].out_degree >> Gtable[i].list.addFront(); // stuck here...the parameter in addFront should be the char that is read in.
    
    		
    		++i;
    	}
    	fin.close();
    Last edited by rjs123; November 10th, 2011 at 12:27 AM.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Reading in input from file

    You should read the every whole line of your file in some std::string bufer (do it in a loop). Then parse the line depending of the value of its second field (how many fields are there till the end of line)
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured