Link to home
Start Free TrialLog in
Avatar of meow00
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\MyMap.cpp(485) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'class std::basic_string<char,struct std::char_traits<char>,class 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 !!!
 
Avatar of OnegaZhang
OnegaZhang

TextOut(mdc, x, y , mystring.c_str(), 4);

welcome to www.fruitfruit.com
ASKER CERTIFIED SOLUTION
Avatar of OnegaZhang
OnegaZhang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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