INT to String

Posted on 2012-03-09
Medium Priority
Last Modified: 2012-08-13
This shouldn't be this difficult....

I have a global variable:

correctKey = 1;

Open in new window

I want to do some debugging, and MessageBox the value sometimes.

So, I init a CHAR with an extra spot for the terminating 0, right?

char ck[2];

Open in new window

then I assign that to the INT value, right?

    ck = correctKey;

Open in new window

Then try to debug message.
    MessageBox(NULL,"Correct Key Is...", ck,NULL);[code]

Open in new window

I have tried using std::string, atoi , c_str() , etc. Apparently, I haven't figured out the right combination.

Question by:edvinson
  • 2
LVL 41

Accepted Solution

Kyle Abrahams earned 2000 total points
ID: 37703347
char ck;

ck = itoa(correctKey);  //  http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/

and not sure if you have to append it as one message:

 MessageBox(NULL,"Correct Key Is..." + ck,NULL);

Author Comment

ID: 37703587
Hmmm, thats not working either.

Author Comment

ID: 37703613
Got it

 int myNumber = 1;

                    char myChar[2];

                    itoa (myNumber,myChar,10);

                    MessageBox(hwndDlg, myChar, "Information", MB_ICONINFORMATION);

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

624 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