|
-
May 31st, 2001, 06:15 PM
#1
Thread Starter
Frenzied Member
Strings to char*
How do you change a string to a char* ?
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 04:32 AM
#2
Frenzied Member
Well in C++ a string is an array of char. Do you mean the <string> class. To make it a c string use :
Code:
string mystr = "string";
mystr.c_str(); // makes it a c string
-
Jun 1st, 2001, 10:25 AM
#3
Thread Starter
Frenzied Member
The problem I have is I got a VAR that is a string (<string>) and I need to pass it to a function that requires a char* or a LPCTSTR. I figure I could loop through the array and passing each char to a temp char array, but I figure there must be an easier way.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 12:35 PM
#4
Frenzied Member
-
Jun 1st, 2001, 12:37 PM
#5
Thread Starter
Frenzied Member
Tried that, said it could not convert from string (acually a long class of char*) to a char*. Maybe I am using it wrong. Example?
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 12:49 PM
#6
Frenzied Member
-
Jun 1st, 2001, 01:03 PM
#7
Thread Starter
Frenzied Member
It actually makes no differnce until I get my class working.
http://161.58.186.97/showthread.php?s=&threadid=79765
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 03:40 PM
#8
Monday Morning Lunatic
string.c_str() returns a const char* pointer to the data string, so you can't change the contents. If you actually want to obtain the data, you need to use strcpy on it. This is another good reason for using const well in your code.
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
-
Jun 1st, 2001, 03:42 PM
#9
Thread Starter
Frenzied Member
DOH!!!
Thats why it dont work. Man I hate making stupid mistakes like that
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 03:48 PM
#10
Monday Morning Lunatic
I really wish they'd make things like that obvious Would've made my life a lot easier 
Anyway, I'm off to look at your other thread now...
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
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
|