Results 1 to 11 of 11

Thread: MessageBox

  1. #1

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650

    MessageBox

    How would i make a messagebox display a variables contents, right now it gives me compile 'cant convert string to char*', and it gives me the smae error when i give it a char* or the & of either.

  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Show me how you call your messagebox
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    i think strings might need to use the string.c_str()

    i think the string class has that

  4. #4

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    #include <windows.h>
    #include <iostream.h>
    #include <string>

    int main()
    {
    string name;
    cout<<"Whats your name?\n";
    cin>>name;
    MessageBox(NULL, name, name, MB_OK);
    return 0;
    }

    thats the chunk

  5. #5
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Originally posted by Mushroom Realm
    #include <windows.h>
    #include <iostream.h>
    #include <string>

    int main()
    {
    string name;
    cout<<"Whats your name?\n";
    cin>>name;
    MessageBox(NULL, name, name, MB_OK);
    return 0;
    }

    thats the chunk
    try:

    PHP Code:
    MessageBox(NULLname.c_str(), name.c_str(), MB_OK); 
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Replace iostream.h with iostream, and add a using namespace std; (use Google to find out, or look round the forums for why).
    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

  7. #7
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Yes, because the new string overloads the operator char * () right parksie?
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nope. There's a good reason why the standard string does *not* have an implicit conversion to char*.

    It messes up all the type-detection, so in the end it's much less useful for optimisations.
    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

  9. #9
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    ooh

    coool
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Quite confusing for people who only used CString all the time...
    Yet it does make a lot of sense.
    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.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    BTW if you care for UNICODE compatibility (easier localization and faster execution in WinNT/2k/XP) you should use this instead of string:

    typedef basic_string<TCHAR> tstring;

    You must still include <string>.
    Use tstring just like string, but also include <tchar.h> and always use the _T() macro to wrap all your literal strings.
    tstrign mystr = _T("Hello, UNICODE!");
    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.

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