2 Replies - 112 Views - Last Post: 05 December 2017 - 07:42 AM Rate Topic: -----

#1 Mar1990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-December 17

Need to display double result to string As table

Posted 05 December 2017 - 05:53 AM

Hello,

I am really sorry if I have a lot of questions, my problem is that I need my output to apear as string . here is my function I need only to change the ligne where I have problem because I will need the resultat_ simulation with table appearance in my projet.
virtual void internalTransition(const vd::Time& /*time*/)
    {

    vector <Patient> myPat;
    vector <Generalist> myGen;
      switch (S_STATE)
     {
    case STATE_1:
       {
    Generalist::fillGeneralist(myGen);
    Patient::fillPatient(myPat);
    S_STATE =STATE_2;
    }

    break;

   case STATE_2;
   {
       for ( int i = 0; i < 20; i++ )
   {
    for ( int j = 0; j < 20; j++ )
    {   double dist = Patient::distance(myPat[i].GetLat(), myPat[i].GetLong(), myGen[j].GetLat(), myGen[j].GetLong() );
        cout << "The distance between patient" << i + 1 << " and doctor " << j + 1 << " is " << dist << "km " << endl;
//ligne where I have problem
        resultat_simulation += myPat[i].GetLat()+"\t\t"+ myPat[i].GetLong()+"t\t"+ dist;
            }
    }
   STATE_2 = IDLE;

            }break;
   }
   }




I have already declared resultat_simulation as string and all parameters that I want to display are double ,

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Need to display double result to string As table

#2 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 659
  • View blog
  • Posts: 2,736
  • Joined: 13-June 14

Re: Need to display double result to string As table

Posted 05 December 2017 - 05:59 AM

You should take a look at std::stringstream.
Was This Post Helpful? 0
  • +
  • -

#3 Mar1990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-December 17

Re: Need to display double result to string As table

Posted 05 December 2017 - 07:42 AM

Hello,

I have found the solution so I need only to declare a function to_String because in MinGW std::to_string() does not exist, so I have to make my own declaration:

string Personne::to_string(int i)
{
    stringstream ss;
    ss << i;
    return ss.str();
}



and also include sstream library

#include <sstream> 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1