Hi guys, so I need to read in a original file that has mutual funds data. Then I have to create a second file and put the data from the original file in there. However the second file should have the headings removed and the hyphens removed, and the commas should be replaced by spaces. I managed to remove the headings and hyphens but I got stuck at removing the commas and replacing them with white spaces. Ive tried multiple things but nothing as worked for me so far, any ideas on how to get rid of the commas and replace them with spaces?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main() {
ifstream infile;
ofstream modifiedFile;
string trash;
char ch, comma;
infile.open("vtsmx.csv");
modifiedFile.open("vtsmxModified.csv");
if(!infile)
{
cout << "Error opening the file" << endl;
return 1;
}
else
{
getline(infile,trash);
while(!infile.eof())
{
ch= infile.get();
if(ch !='-') modifiedFile <<ch;
comma= infile.get();
if(comma!=',') modifiedFile <<comma;
}
/* while(!infile.eof())
{
comma= infile.get();
if(comma!=',') modifiedFile <<comma;
}
*/
cout <<"done";
}
return 0;
}
|
Ex of original file
Date,Open,High,Low,Close,Adj Close,Volume
2015-10-16,50.860001,50.860001,50.860001,50.860001,49.009617,0
2015-10-19,50.880001,50.880001,50.880001,50.880001,49.028889,0
2015-10-20,50.810001,50.810001,50.810001,50.810001,48.961437,0
Ex of what I need
20151016 50.860001 50.860001 50.860001 50.860001 49.009617 0
20151019 50.880001 50.880001 50.880001 50.880001 49.028889 0
20151020 50.810001 50.810001 50.810001 50.810001 48.961437 0