Solved

INT to String

Posted on 2012-03-09
3
358 Views
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.

Thanks,
0
Comment
Question by:edvinson
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 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);
0
 
LVL 1

Author Comment

by:edvinson
ID: 37703587
Hmmm, thats not working either.
0
 
LVL 1

Author Comment

by:edvinson
ID: 37703613
Got it

 int myNumber = 1;

                    char myChar[2];

                    itoa (myNumber,myChar,10);

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TTimer no longer functioning 7 90
Getting IP address 8 77
mixing C++ & C# in Vis Studio 2013 7 171
How to copy an image file into clipboard C/C++? 1 168
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

776 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