I am trying to resort a few lines in "Main.txt" to another file, "Main1.txt".
The lines look like this in "Main.txt":
12/03/1999,12/04/1999,1535
12/03/1999,12/04/1999,1537
12/03/1999,12/04/1999,1538
When using this code my output look like this:
It seems that string/int Two/Three did work but not One
I beleive it has to do with getline in anyway but cant figure it out really ?
12/04/1999,1535,2,12/03/1999
12/04/1999,1537,2,03/1999
12/04/1999,1538,2,03/1999
Code:#include "stdafx.h" #include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <limits> #include <ios> #include <cstdio> using namespace std; int main() { char Comma; std::string One = ""; std::string Two = ""; int Three = 0; ofstream NewOutFile; ifstream NewFile ("Main.txt"); NewOutFile.open ("Main1.txt"); while ( getline(NewFile, One, ',') ) { NewFile >> Two; NewFile >> Comma; NewFile >> Three; NewFile.get(); // read in trailing newline character NewOutFile << Two << ',' << Three << ',' << One << "\n"; } return 0; }