Solved

INT to String

Posted on 2012-03-09
3
349 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 39

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

759 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

18 Experts available now in Live!

Get 1:1 Help Now