Solved

TextOut in VC++

Posted on 2004-10-17
3
521 Views
Last Modified: 2006-11-17
Hi Experts,

  This is actually a continuous question of :
   http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21170689.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 !!!
 
0
Comment
Question by:meow00
  • 2
3 Comments
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12336192
TextOut(mdc, x, y , mystring.c_str(), 4);

welcome to www.fruitfruit.com
0
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 300 total points
ID: 12336198
TextOut(mdc, x, y , mystring.c_str(), mystring.length());

welcome to www.fruitfruit.com
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12336985
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
 
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question