Re: [gtkmm] convert double to char



>> 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());

all true. however, if you can find me any value of a double that will
not fit into a 32 character representation, i'd like to see it. in
addition, snprintf() also makes a buffer overrun impossible in more or
less the same way. the overhead of stringstreams can be quite
significant, which is why i tend to avoid using them.

--p



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