Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load from string #91

Closed
jtaylorme opened this issue Apr 10, 2021 · 2 comments
Closed

Load from string #91

jtaylorme opened this issue Apr 10, 2021 · 2 comments

Comments

@jtaylorme
Copy link

jtaylorme commented Apr 10, 2021

Sorry to bother you again but after a couple of hours of beating my head against the wall I thought I would ask...below things are somewhat cobbled together and isn't what my code looks like exactly but just to show you what I am doing and the pieces involved. I have been loading from a file but decided having an option to load from a string would be useful. I keep getting the "ios_base::failbit set: iostream stream error". The csvstring gets passed in as a string parameter to the function. Can you see what I am doing wrong? I have tried a number of different things but always the same result. Thank you.

Jim

`rapidcsv::Document doccsv(stringstream(""), rapidcsv::LabelParams(0, -1),
rapidcsv::SeparatorParams(',' ,false,rapidcsv::sPlatformHasCR ,false,true ));

string csvstring = "27502 919 35.74801 - 78.83401 A, PE, X NC Wake E 8374\r\n27511 919 35.75124 - 78.70732 CARY NC Wake E 8812";

std::stringstream  sstream(csvstring);
doccsv.Load(csvstring, rapidcsv::LabelParams(cindex, rindex),
         	rapidcsv::SeparatorParams(delimiter[0] /* pSeparator */,
		    trimit /* pTrim */,
	   	    rapidcsv::sPlatformHasCR /* pHasCR */,
		    false /* pQuotedLinebreaks */,
		    quoteit /* pAutoQuote */));`
@d99kris
Copy link
Owner

d99kris commented Apr 11, 2021

Hello @jtaylorme - I think the main problem in the provided code is that Load() is called with csvstring argument, rather than sstream. If I change the code to the following it seems to work (at least not throw exception):

  rapidcsv::Document doccsv;
  
  std::string csvstring =
    "27502	919	35.74801 - 78.83401	A, PE, X	NC	Wake	E	8374\r\n"
    "27511	919	35.75124 - 78.70732	CARY	NC	Wake	E	8812";

  std::stringstream sstream(csvstring);
  doccsv.Load(sstream, rapidcsv::LabelParams(0, 1),
              rapidcsv::SeparatorParams(',' /* pSeparator */,
                                        false /* pTrim */,
                                        rapidcsv::sPlatformHasCR /* pHasCR */,
                                        false /* pQuotedLinebreaks */,
                                        true /* pAutoQuote */));

There's another Github issue #63 reported suggesting rapidcsv should provide more developer friendly exceptions. I hope I can find time to look into implementing that soon.

@jtaylorme
Copy link
Author

Once again I must apologize. I knew it would be something blatantly obvious...those are hardest to find for me. Thanks again.

Jim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants