Need to display double result to string As table

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.

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
   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
Last edited on
std::to_string to convert double to string
http://en.cppreference.com/w/cpp/string/basic_string/to_string

resultat_simulation += to_string(myPat[i].GetLat())+"\t\t"+ to_string(myPat[i].GetLong())+"t\t"+ to_string(dist);
Hello,


It is okey now, I added also this function because in MinGW std::to_string() does not exist, so I have to make my own declaration

1
2
3
4
5
6
string Personne::to_string(int i)
{
    stringstream ss;
    ss << i;
    return ss.str();
}


alse I included in the header sstream library
 
#include <sstream> 


Thank you a lot
I added also this function because in MinGW std::to_string() does not exist

It probably does exist, you just have to enable C++11 mode.

add this to the compiler options:
 
-std=c++11 


If that doesn't work, then the compiler is really old, you might look at updating it.

I should add though that using stringstream is ok as a workaround, and may offer more flexibility over how the result is formatted.
Last edited on
Hello,

@chervil I tried and it works thank you for your help
Registered users can post here. Sign in or register to post.