|
-
Sep 25th, 2002, 05:45 PM
#1
Thread Starter
Fanatic Member
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.
-
Sep 25th, 2002, 06:29 PM
#2
Fanatic Member
Show me how you call your messagebox
-
Sep 25th, 2002, 06:55 PM
#3
Frenzied Member
i think strings might need to use the string.c_str()
i think the string class has that
-
Sep 26th, 2002, 05:23 PM
#4
Thread Starter
Fanatic Member
#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
-
Sep 26th, 2002, 05:33 PM
#5
Fanatic Member
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(NULL, name.c_str(), name.c_str(), MB_OK);
-
Sep 26th, 2002, 06:08 PM
#6
Monday Morning Lunatic
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
-
Sep 26th, 2002, 06:26 PM
#7
Fanatic Member
Yes, because the new string overloads the operator char * () right parksie?
-
Sep 26th, 2002, 06:37 PM
#8
Monday Morning Lunatic
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
-
Sep 26th, 2002, 06:57 PM
#9
Fanatic Member
-
Sep 27th, 2002, 05:19 AM
#10
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.
-
Sep 27th, 2002, 05:22 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|