Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ getline adding spaces
    primarykey
    data
    text
    <p>I have been trying to fix this problem for days and I can't get it. Basically my code is supposed to read a .csv file produced by wmic and save it to a struct. I can read the data and it is being stored, but the data has an extra space after each character. I have tried switching to the Unicode versions of the functions and using wide strings but they only messed up the data even more (they turned a "n" into a "ÿ"). </p> <p>Here is the code that I think is the issue:</p> <pre><code>system("wmic product get name,version,installdate,vendor /format:csv &gt; product.txt"); std::ifstream infoFile("./program.txt"); // The file wmic wrote in csv format. if(infoFile.is_open()) { std::string line; int lineNum = 0; while(getline(infoFile, line)) { lineNum++; std::cout &lt;&lt; "\nLine #" &lt;&lt; lineNum &lt;&lt; ":" &lt;&lt; std::endl; Program temp; std::istringstream lineStream(line); std::string cell; int counter = 0; int cellNum = 0; while(getline(linestream, cell, ',')) { cellNum++; std::cout &lt;&lt; "\nCell #" &lt;&lt; cellNum &lt;&lt; ":" &lt;&lt; cell &lt;&lt; std::endl; switch(counter) { case 0: break; case 1: temp.installDate = cell; break; case 2: temp.name = cell; break; case 3: temp.vendor = cell; break; case 4: temp.version = cell; break; default: std::cout &lt;&lt; "GetProductInfo(): Invalid switch value: " &lt;&lt; counter &lt;&lt; std::endl; break; } counter++; } information-&gt;push_back(temp); // Vector to save all of the programs. } infoFile.close(); } else { std::cout &lt;&lt; "GetProductInfo(): Failed to open the input file." &lt;&lt; std::endl; return 1; } return 0; } </code></pre> <p><strong>Edit:</strong> O.K., I am trying to write the BOM (FF FE 0D 00 0A) as it wasn't being written before. I am writing a char array with the hex values but there is a extra 0x0D being added (FF FE 0D 00 0D 0A). It is also saving internal variables with the extra spaces. That <em>might</em> not be an issue as I can modify my code to account for it but that wouldn't be optimal. Any ideas?</p> <p><strong>Edit2:</strong> So I guess I don't need the BOM. My main problem now is just reading the UTF-16LE file and saving the data to a struct without the extra spaces. I need some help doing it the <em>right</em> way as I would like to figure out how to prevent this in the future. Thanks for you help everyone, this bug is critical.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload