Solved

TextOut in VC++

Posted on 2004-10-17
3
518 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
Comment Utility
TextOut(mdc, x, y , mystring.c_str(), 4);

welcome to www.fruitfruit.com
0
 
LVL 12

Accepted Solution

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

welcome to www.fruitfruit.com
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now