0

this is my infile's data..How do I get info into various data types? extraction operator?

I know extraction works but the 5th line throws me for a loop..Thanks for help;

11/29/2010 S 2907 1
11/29/2010 S 9673 4
11/30/2010 A 4321 30
11/31/2010 S 9673 12
12/01/2010 N 5789 wind_chimes 13.54 17.83
12/02/2010 S 5140 5

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by chiwawa10
0

There are generally 2 different strategies for reading a file; read the file line-by-line (which preserves the white spaces) using getline() and then parse the line into the stuff you need, or read the file word at a time using the >> extraction operator, which is white space delimited.

Edited by Clinton Portis: n/a

0

It seems like your fifth line is of different format from the rest. Its really difficult to work with file of this kind as its data can take many forms.

This is a general rule: For you to read data from file, you'll need to know the format beforehand. The reason is simple; so that you'll know how to process the data and what it means.

Take your sample data as an example, the data "wind_chimes" seems to belong to the same group of data as "1", "4", "30", "12" and "5". To my understanding, the data anticipated here is an integer. But all of a sudden, characters were encountered. So, its really hard to process unformatted data.

Hope this helps.

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.