Jump to content

TextOutW and Variables

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
intrinsik4

intrinsik4

    Newbie

  • Members
  • Pip
  • 1 posts
I'm new to programing, period.

I'm working with the default Microsoft MFC Application template in Visual Studio 2008.

Using pDC->TextOutW, I'm trying to get a variable (an int or a double) in place of the LPCTSTR.

void CFibbiMFCView::OnDraw(CDC* pDC)
{
CFibbiMFCDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

// TODO: add draw code for native data here
double x = 1;
pDC->TextOutW(10,10,x);
}

This (obviously to likely all of you) doesn't work. Is there a way to change the integer to what TextOutW wants? Or should I be going about this a whole other way?

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
You need to convert your integer into a Unicode string first. I would look into using an ostringstream.

#include <sstream>
#include <string>

using std::ostringstream;
using std::string;

ostringstream mystream;
string newstring;
int x = -5;

mystream << x;
newstring = mystream.str();
//newstring now contains "-5".

sudo rm -rf /