d99kris / rapidcsv

C++ CSV parser library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using String for Input

jtaylorme opened this issue · comments

First. Thanks for all the work on this project. It is nicely done.

Second. Hopefully I am not missing something obvious and wasting your time but given the following:

string txt_all = "1,2,3,4,5,6";
rapidcsv::Document csv_doc(txt_all, rapidcsv::LabelParams(-1, -1),
rapidcsv::SeparatorParams(delimiter[0] /* pSeparator /,
false /
pTrim /,
rapidcsv::sPlatformHasCR /
pHasCR /,
false /
pQuotedLinebreaks /,
true /
pAutoQuote */));

Can you help me see why this fails? I get a RunTime Library error. "This application has requested the Runtime to terminate in an unusual way...."

Using the exact some code with a file works fine. I only have this problem with a "string". Thanks.

Jim

Also, if I submit this it works fine as well.
istringstream(txt_all)

Jim

Hi @jtaylorme - the Document() constructor accepts either a std::string containing a file path to a CSV file or a std::istream pointing to a stream of CSV data.

The way to read CSV data stored in a std::string is to use a string stream, as you've found. It's documented in the README as well.

I see now and how I misinterpreted the string overload. Thank you.

Jim