Solved

TextOut in VC++

Posted on 2004-10-17
3
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

696 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