How would you do this better? (file i/o)

This is a discussion on How would you do this better? (file i/o) within the C++ Programming forums, part of the General Programming Boards category; howdy boyz: ok here is what i'm trying to do. the file format i bring into the program is as ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    63

    How would you do this better? (file i/o)

    howdy boyz:

    ok here is what i'm trying to do. the file format i bring into the program is as follows:

    Code:
    Source1 : Vertex1 12 Vertex2 8 Vertex3 9
    Source2 : Vertex1 3
    Source3 :
    Source4 : Vertex1 2 Vertex4 92
    I want to pull each of these into a variable, that is going to be stored into my adjacency list for the graph. This is a problem as i only seem to get the source colon first vertex and first cost for any given line (with my current mehtod) my question is how to loop through the rest of the line in order to catch te rest of my input file lines.. my code is as follows, assuming i open the file to a variable 'in'

    Code:
    string oneLine;
    while( getline(in, oneLine) )//reads the input file line into a 
                                               //temp string called oneLine
    {
    string source, colon, dest;
    int cost;
    in >> source;//this is the source for any given line
    in >> colon;//this is the colon fall through
    //I THINK I NEED TO LOOP THIS BUT HOW?
    in >> dest;//pulls the first dest value
    in >> cost; // pulls the cost value for a given node
    }//closes while loop
    now this is just to get the file into the program, i know that i'll need to add my adjacency list code after these, but i can't run without walking first..

    thanks fellas

  2. #2
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    I just post code for a parsing stream readr written in java that read a line and then returns an array of strings. The code is here: http://www.cprogramming.com/cboard/s...threadid=14217

    You should be able to convert it to C++ and incorporate it into you code to get every thing in the line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-31-2004, 12:21 AM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 09:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21