1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Rep Power

    Question ifstream - text input into char and int

    I'm having difficulty correctly parsing data from a text file. The text file is roughly divided into two colums. The first column contains a char, the second column an int. I defined a variable inFile as type ifstream. I can pull all the data line by line using:

    while (getline(inFile, s))

    Unfortunately, I don't have a clue as to how I can correctly extract the required information from this point.

    I suppose its possible to pull the data one char at a time.

    inFile >> chara >> intb;

    Unfortunately, when I do this, my program spits out erroneous data.

    Am I approaching this problem correctly or am I way off and there is a simpler, cleaner way to parse data from a text file? Any pointers would be helpful.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Somewhere in the great unknown
    Rep Power
    You can always try to break each string into tokens. This is assuming you know what is being used as the file's delimiter.
    Check out the strtok function. I would play around with it a good deal before using it in a real program though because it can be dangerous if used incorrectly. For the safest path, copy the variable to a temp variable and perform the strtok on it.

IMN logo majestic logo threadwatch logo seochat tools logo