Monday 15 June 2015

Files with commas in c++ -


How to read in a text file with a comma and write it in a new file without any commas?

The file has nine columns - the first month is the next date and a comma, then the year is 6 columns of those numbers that represent the dollar with comm, for example 17,751.24

I need to create a new text file from which there is no comma.

I was trying to use double variables for each callum, but comma forced me to use string variables, then I tried to read it with a loop for a while: Gt; & Gt; Date & gt; & Gt; Years & gt; & Gt; Open & gt; & Gt; High & gt; Less & gt; Close & gt;

  While (infile> gt; gt; & gt; adj) {...}  

Side note: File some stock Exchange is about cheese.

How do I create a new one? There should be no comma except the text file with the same content.

This is for the initial C ++ class, so please do not use advanced material in the answer.

Thanks in advance.

Maybe it's too early now, That's it can help you go in.

The simple question is:

How to read and write with a comma in a text file for a new file without any commas?

This simple question is comprehensive (in many ways), but you can consider the following:

  // to use: // Example with an I / O redirection // Example with the executable name t160 // and some file named 'inputFile': // // t160 & lt; Input File & gt; NoCommaFile // int t160 () {int commaCount = 0; Do {int kar = 0; Car = std :: cin.get (); // read the single char from cin if (std :: cin.eof ()) {break; } // When we end, we end (std :: cin.bad ()) {// file I / o error std :: cerr & lt; & Lt; "ERR: std :: cin.bad ()" & lt; & Lt; Std :: endl; break; } If (',' == car) {commaCount + = 1; to continue; } // // found a comma ^^^^^^^^ loop release: coma std :: cout & lt; & Lt; Four (tax); // no commas, so car quotes} while (1); // Simulation for testing: // std :: cerr & lt; & Lt; "Commount =" & lt; & Lt; Commacount & lt; & Lt; Std :: endl; Return (0); }  

This code reads one letter at a time, and writes anything one or the other at a time.

When a comma is found, then it is 'abandoned'.

You can decide later that you want to change the comma with space (it can be canceled) Instead)

I can think that you might decide to behave differently from commas-digit (",") with commas-digit (as in "123,456").

This simple loop should support those decisions, and many more.

Good luck.


No comments:

Post a Comment