Hello guys I am a novice at C++, however I have this project for school. I am trying to read a CSV file using C++ visual studio and store each value into string and output it to a file. I am using commas as the delimiter but when it reaches ("2,156,624,900",) it doesn't store properly as it reads to the comma and stop example "2 is stored. How could the code be edited to store 2,156,624,900 instead or is there a way I could avoid the first line and store the rest of values with the quotation marks as the delimiter for that value. If there is any questions you could ask. The following is the code I am using.
Here's an idea. The CSV part may be a little over-complicated (?), and it's not perfect, but I think it'll do what you want. I only tested it with three fields and output files. You can add the rest.
Sorry, it is not C++ ready to use, it is an excerpt from a pipe stage I once used on VM/CMS. At least the comments could give you an idea what you should to bear in mind when using CSV seriously:
if ph = '' then ph = 'NixBix' /* default place holder for "" */
'CALLPIPE (sep % end § name CSVCLN.REXX) *:', /* ------- in ------ */
'% change /""""/'ph'/', /* single inch-sign */
'% change /'oc'"""/'oc'"'ph'/', /* leading inch-sign */
'% change 1.3 /"""/"'ph'/', /* same in fst column */
'% change /'oc'""/'oc'/', /* empty cells */
'% change 1.2 /""//', /* same in fst column */
'% change /""/'ph'/', /* example: "zizu = 8"" etc." */
'% strip trailing' oc, /* no empty cells at end of record */
'% xlate 1-* 40 00', /* Mask the blanks. */
'% tokenize /"/ x01', /* Tokenize and delimit. */
'%q:outside /"/ /"/', /* branch quoted values */
'% xlate 1-*' oc nc, /* replace old by new sep-char */
'%f:faninany', /* collect all parts of record */
'% deblock linend 01 terminate', /* Re-form original records. */
'% change /'ph'/"/', /* place holder to inch-sign */
'% xlate 1-* 00 40', /* Unmask the blanks. */
'%*:', /* ----------- out ----------- */
'§q:', /* from OUTSIDE */
'% nfind "' !!, /* Get rid of the quotes. */
'%f:' /* to FANINAY */
failure:; error: exit (RC * (RC ^= 12 & RC ^= 8)) /* RC = 0 if EOF */
Being myself a beginner in C++ I am not yet in the position to quickly redo this on the PC without piping.
BTW, CSV listings are used for long term archiving data. Even if old tools won't work any more on future platforms, it is quite simple to program new interpreters for it. Now prove it! ;)
In this RFC it says that a double-quote inside double-quotes should be escaped by another double-quote. In the program I posted above I escaped it with a backslash.
The above excerpt from my pipe stage is now 20 years old. I was not aware of the RFC you mention, I was driven by the need to get useful data out of the tables I got from subcontractors and internal collaborators. With useful I mean useful for me (and the tools I used on the mainframe).