Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TextOut in VC++

Posted on 2004-10-17
3
Medium Priority
?
540 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 1200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  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 …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 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