I am trying to sort these lines from a .txtfile:
12/01/2000,1649
12/01/1998,1746
12/01/1997,1846
12/01/1996,1946
The output is right but with lines inbetween. It should not be blank lines inbetween. I cant figure it out what it depends on.
Output:
12/01/1996,1946
12/01/1997,1846
12/01/1998,1746
12/01/2000,1649
Code:#include "stdafx.h" #include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> #include <cmath> #include <algorithm> struct Value { int Action; std::string Symbol2; }; using namespace std; int main () { int t = 0; std::string Symbol; int Action = 0; std::vector<Value> Values (5); ofstream Sort1; Sort1.open ("Sort1.txt"); ifstream Sort ("Sort.txt"); while ( getline(Sort, Symbol, ',') ) { t = (t + 1); // Count Sort >> Action; Values[t].Symbol2 = Symbol; Values[t].Action = Action; } std::sort(Values.begin(), Values.end()); for (int Rowsen = 1; Rowsen < (t + 1); Rowsen++) //Number of Lines { Sort1 << Values[Rowsen].Symbol2 << ',' << Values[Rowsen].Action << "\n"; } return 0; } bool operator < (const Value& x, const Value& y) { return ((x.Symbol2 < y.Symbol2) || (x.Symbol2 == y.Symbol2 && x.Action <= y.Action)); }



LinkBack URL
About LinkBacks



