Results 1 to 5 of 5

Thread: Combining Variables

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    How would I do something like this:
    PHP Code:
         int score;
         
    char bufferScore[4];
         
    itoa(scorebufferScore10);
         
    MessageBox... 
    I want it to say "Your score is (whatever it is), good job!" or something like that...in vb its the &, what is it in C++

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    #include <iostream.h>
    #include <windows.h>
    
    int main(int argc, char* argv[])
    {
    int score = 5555;
    char bufferScore[5];
    itoa(score, bufferScore, 10);
    char allText[] = "Your score is ";
    strcat(allText,bufferScore);
    strcat(allText," good job");
    MessageBox(NULL,allText,"ok",MB_OK);
    return 0;
    }
    or use the string class (much easier)
    Code:
    #include <string>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    string t1 = "text1";
    string t2 = "text2";
    string all  = t1+t2;
    MessageBox(NULL,all.c_str(),"Caption",MB_OK);
    return 0;
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Just what I wanted...Thanks Vlatko!

    (Damn you John/James, now I'm gonna go smilie happy! )

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Or how about my printf-style MsgBox function?
    Code:
    int MsgBox(HWND hParent, int iFlags, TCHAR *pcCaption, TCHAR *pcText, ...) {
    	va_list args;
    	TCHAR pcBuf[1024];
    
    	va_start(args, pcText);
    	_vsntprintf(pcBuf, 1024, pcText, args);
    	va_end(args);
    	return MessageBox(hParent, pcBuf, pcCaption, iFlags);
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    That format string code is really nifty. I like I've seen it before, here and other places too, but it's still kinda cool

    Geeky huh?
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width