meow00
asked on
TextOut in VC++
Hi Experts,
This is actually a continuous question of :
https://www.experts-exchange.com/questions/21170689/write-words-on-the-screen.html
I tried to use TextOut to print a string on the screen :
-------------------------- ----------
string mystring ;
mystring = "Hello" ;
TextOut(mdc, x, y , _T(mystring), 4);
-------------------------- ---------- ---------- -----
but it didn't work : I got the errors :
:\Program Files\Microsoft Visual Studio\MyProjects\MyMap\My Map.cpp(48 5) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'class std::basic_string<char,str uct std::char_traits<char>,cla ss std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
-------------------------- ----------
Does anyone know what I might have missed and how to fix it ??? thanks !!!
This is actually a continuous question of :
https://www.experts-exchange.com/questions/21170689/write-words-on-the-screen.html
I tried to use TextOut to print a string on the screen :
--------------------------
string mystring ;
mystring = "Hello" ;
TextOut(mdc, x, y , _T(mystring), 4);
--------------------------
but it didn't work : I got the errors :
:\Program Files\Microsoft Visual Studio\MyProjects\MyMap\My
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
--------------------------
Does anyone know what I might have missed and how to fix it ??? thanks !!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In a MFC project you should consider using CString rather than std::string as you wouldn't have compatibility problems like that above:
CString mystring ;
mystring = "Hello" ;
TextOut(mdc, x, y , _T(mystring), 4); // no problems with CString
There is a CString::operator LPCTSTR() that can convert any CString to a LPCTSTR (const TCHAR*), but there isn't an equivalent function in std::string.
Regards, Alex
CString mystring ;
mystring = "Hello" ;
TextOut(mdc, x, y , _T(mystring), 4); // no problems with CString
There is a CString::operator LPCTSTR() that can convert any CString to a LPCTSTR (const TCHAR*), but there isn't an equivalent function in std::string.
Regards, Alex
welcome to www.fruitfruit.com