Re: [gtkmm] convert double to char



On Monday 01 December 2003 10:29 pm, Paul Davis wrote:
>

[snip]
> >Anyone know how can I make this code work :
> >
> >[code]
> >double DegreeLong=1.2011;
> >   m_Entry2.set_text(DegreeLong);
> >[/code]
>
> this is an extremely basic C++ question. really way too basic and
> general for this list.
>
> 	char buf[32];
>
> 	snprintf (buf, sizeof(buf), "%g", DegreeLong);
> 	m_Entry2.set_text (buf);

Indeed so, but as we are using C++, stringstreams seem a better choice, and 
make buffer overruns impossible:

  std::ostringstream strm;
  strm << DegreeLong;
  m_Entry2.set_text(strm.str());

Chris.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]