Reading in input from file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Reading in input from file

  1. #1
    Join Date
    Feb 2011

    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 A in the first line
    The second is the # of vertices it is connected to (out-degree) 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 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.

                    ifstream fin;"table.txt");
    	int i = 0;
    		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.
    Last edited by rjs123; November 9th, 2011 at 11:27 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)