0

I've spent over an hour on this and I still cannot get the data in the way that I want it. Really frustrating because this is so easy. My output right now is this:

    0.00 miles: 3Wartburg_TN                            
   37.64 miles: 2Knoxville_TN                          37.64
  671.37 miles: 5New_York_NY                          633.72
 4547.77 miles: 27Frankfurt_DE                        3876.40
 7597.51 miles: 23Lagos_NG                            3049.74

and the output I want is this:

    0.00 miles :   3 Wartburg_TN
   37.64 miles :   2 Knoxville_TN            37.64 miles
  671.37 miles :   5 New_York_NY            633.73 miles
 4547.77 miles :  27 Frankfurt_DE          3876.40 miles
 7597.51 miles :  23 Lagos_NG              3049.74 miles

I can not for the life of me figure out how to get the correct output. Here's what I have so far for the code. Am I not using right and left justified correctly?

 cout <<fixed <<setprecision(2) <<setw(8) << right << vdist[ij] << " miles: "  
      << ij << setw(25)    << left << vec[ij].cityname
    << setw(18) << right << vedge[ij]<<endl;
taocp
  • 23,276
  • 10
  • 49
  • 62
Mdjon26
  • 2,145
  • 4
  • 19
  • 29
  • 2
    Without showing the code, how could we tell? – crashmstr Mar 13 '14 at 15:39
  • you forgot the code. But what you probably want is [std::setw](http://en.cppreference.com/w/cpp/io/manip/setw) or something like [bprint](https://github.com/dattanchu/bprinter/wiki) – Dmitry Ledentsov Mar 13 '14 at 15:39
  • 1
    You output `ij` that is right justified, then immediately `cityname` that is left justified with no space between them – Cory Kramer Mar 13 '14 at 15:41
  • 2
    surely there are things you can fix yourself before posting: space after miles and numbers, adding `miles` to the end, etc... actually I'm not even sure what the question is... – Karoly Horvath Mar 13 '14 at 15:42

1 Answers1

4
 cout << fixed << setprecision(2) 
      << setw(8) << right << vdist[ij] 
      << " miles : "  
      << setw(3) << right << ij << " "
      << setw(25) << left << vec[ij].cityname << " "
      << setw(18) << right << vedge[ij] << " miles" <<endl;
  • Not tested
Salgar
  • 7,687
  • 1
  • 25
  • 39