15.5    Ten Carat               12:30   Sedg     Yorkshire Evening Post Phil Rostron    -12.64
5.5     Chip N Pin              1:35    Sedg     News of the World Pegasus      +2.10
5.5     Chip N Pin              1:35    Sedg     Newcastle Journal Doug Moscrop         -6.00
4       Serabad                 1:35    Sedg     Irish Post David Thorpe        +0.50
3.85    Malt De Vergy           2:10    Sedg     The Mail On Sunday John Martin         -8.00
6.2     Blast The Past          2:45    Sedg     Evening Press, York Ebor       -6.20
19      Middleway               3:20    Sedg     Liverpool Daily Post Chris Wright              +14.25
7.6     Looking Forward         3:20    Sedg     The People Larry Lynx  +7.42

Hi, I'm trying to read in a table in the form above and store them in arrays (they are horse racing guides). However as you can see some of the names are two or three sylables and some of them are only one. I would like the names to be stored as one entry. Any ideas?

Below is the code I'm using...

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>

using namespace std;

int main ()  {
   ifstream input;

   int i =0;
   string c;
   string store[100];  

    while (! inputH.eof()){
          input >> c;
          cout << store[i] << endl;

Edited by mike_2000_17: Fixed formatting

10 Years
Discussion Span
Last Post by WaltP

1) don't use eof() to control the loop.

2) Read the file line by line using getline(), not >>.

3) Once the line is read in parse by the following cycle: look for first space, then look for next digit, then ignore the rest It's not the most straightforward line to parse, but it's not impossible either.


1) don't use eof() to control the loop.

Why not? Don't you think an explanation would be more helpful rather than simply dictating to posters? It might actually teach them something.
phvan, see this ( feof() is identical to .eof() .

2) Read the file line by line using getline(), not >>.

Again, why not?
phvan, >> will only read up to the first SPACE so will not read an entire line, nor a multiple "sylable" name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.