Results 1 to 5 of 5

Thread: numbers to string

  1. #1

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238

    numbers to string

    if you want to print numbers in MessageBox() or TextOut(), how do you do this? i mean not just a number, but putting a variable into the parameter of the aforementioned functions.

    thanks,
    jmiller

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Code:
    char tmp[30];
    int i = 32;
    sprintf(tmp,"%d",i);
    MessageBox(hWnd,tmp,NULL,MB_OK);

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    ostringstream tmp;
    int i = 32;
    tmp << i;
    MessageBox(hWnd,tmp.str().c_str(),NULL,MB_OK);
    Get the full power of streams
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    sorry, but that doesn't answer my question.

    what i really need to do is add a number on to a string. In VB it would have been like:
    dim z as String
    dim x as integer

    z = "blah"
    x = 1
    z = z & x

    and CornedBee, for some reason my compiler(vc++6) doesn't recognize ostringstream. what header do i include?

  5. #5

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    nevermind, i've got it. i didn't include <sstream>

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