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

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.