0

hello I'm needing help with parsing data from a CSV file the data is as followed

make,model,year,milage,cost
chevy,Silverado,2009,15,20000
ford,mustang,2017,25,35000

once I do this I have some get and set function that relate to the column names that will grab the data to do something else with it. the data will be coming in continuously so I need this function to always know which spot to grab after each line. worried about CRLF at the end of lines

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • If you use [`std::string`](http://en.cppreference.com/w/cpp/string/basic_string) and [`std::getline`](http://en.cppreference.com/w/cpp/string/basic_string/getline) there are less things for you to worry about. – Some programmer dude Mar 24 '17 at 14:20
  • And if you read [the `std::getline` reference](http://en.cppreference.com/w/cpp/string/basic_string/getline) thoroughly you will notice it can use any characters as "end of line", meaning with an [`std::istringstream`](http://en.cppreference.com/w/cpp/io/basic_istringstream) object you can use `std::getline` to parse each line and separate into its parts. – Some programmer dude Mar 24 '17 at 14:21
  • The almost *brute-force* techniques is to read the text line into a string, search for comma character, extract the substring, convert to integer if necessary. Search your favorite C++ reference for the `std::string` class and see if there are any methods that may be useful. – Thomas Matthews Mar 24 '17 at 14:36
  • I'm still having trouble with this I can read the lines of csv file and fine the endings with '\n' but now I cant figure out how to get the commas and the column names out and then transform the data to it appropriate type and to the assigned variable I declared. – looneytunes24 Mar 24 '17 at 22:30

0 Answers0