Skip to main content
gamedev.net
🔒 Locked

Float to String, Unicode?

Started by DefCom 3 replies 550+ views
Original Post
DefCom
DefCom
I hope someone can help, i have been at this for too many hours to say. I am writing a small track timer application for a Pocket PC using embedded VC++. When i try to Send the time elapsed data to a Static Control, it appears as jibberish (square boxes mainly). The code i use is

char time[10];
float t = timer.getTimeElapsed();
_gcvt(t, 10,time);		
SendMessage (hwndTimeC, WM_SETTEXT, 0, (LPARAM) time);
				
I have tried this in a console app in VC6 and it is ok, so i am assuming it is the string conversion. Any advise would be much appriciated. Thanks.
PHRICTION
PHRICTION
Are you using unicode?

If so you will have to use ''WCHAR'' (or better yet, ''TCHAR''), in place of char. And I don''t this you can use _gcvt because it deals with chars. Try wsprintf mabye.

Hope that helps.
DefCom
DefCom
Thanks for the responce,
I realised as soon as i presses post that a sprintf may work,

the following code does it.


TCHAR szTime[10];
float t = timer.getTimeElapsed();
wsprintf(szTime, TEXT("%.5f"),t);
SendMessage (hwndTimeC, WM_SETTEXT, 0, (LPARAM) szTime);
Qw3r7yU10p!
Qw3r7yU10p!

#include <sstream>

template<typename T>
std::wstring toWString(const T& obj) {
std::wstringstream ss;
ss << obj;
return ss.str();
}


[edited by - petewood on September 9, 2003 5:56:17 AM]
Lektrix
Lektrix
quote:
Original post by petewood

#include <sstream>

template<typename T>
std::wstring toWString(const T& obj) {
std::wstringstream ss;
ss << obj;
return ss.str();
}



Or implement a generic function by using templated std::basic_string/std::basic_stringstream (std::string/std::wstring are std::basic_string typedefs).

OP: boost::lexical_cast

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on September 9, 2003 10:54:13 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.