I can't find information of using a text file as input. The file contains data types of string with spaces, string with spaces, int, and double.
I am using a array of obects with each object housing string with spaces, string with spaces, int, and double variable. I can get the program to compile, but the output just displays the data from the default constructor for each instance of the array.
I know my problem is related the capturing a string with spaces and using a delimiter in a file. I can't seem to find any useful info that helps my problem.
How do I capture data from a text file formatted as below:
text text text,abc def,100,10.99
text text, rst abc,50,5.99
text text text text,abc def,100,10.99
Well, there is a difference of opinion on how to solve your prob.
Personally, I would read the file line by line. split the values, and then convert the value types as required.
If you're wanting to carry of using the extraction operator to read the numbers, you'll need to use something like cin.getline() to read the text (it takes an optional param which defines the stop character).
I just want to throw my two cents in, andywestken is giving you good advice. It may seem complicated when you read what he wrote but in fact the string library has native functions to accomplish what he is suggesting: http://www.cplusplus.com/reference/string/string/find/
From what it looks like your data is in what is called "CSV" format, that is "Comma Seperated Value". Parsing data that is presented like this is well documented on the internet.
@ andywestken: I think you'd do as much good by contributing an Article to this site. There was a small movement here during the last upgrade to have some of the regulars contribute expansions to the tutorials but that never went anywhere so I have a feeling the Admin isn't interested.