|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm playing around with some sockets and most of the c based commands utilise char buf[BUFSIZE]. I've been using c++ strings and sending &string[0] whenever a char * is required. I'm aware that a buf can be a string or not depending on wether is is null terminated but is it a bad idea to force a c++ string object into a char buf[]?
![]() |
|
#2
|
||||
|
||||
|
why dont u just convert it out of the C++ string to a C string?
__________________
microsofts butterfly is their way off telling u their systems have a **** load of buggs Advocating Linux Guide Lesbian Linux Great & Practical Computer Books like the links? |
|
#3
|
||||
|
||||
|
It is a bad idea only if the function alters the char buffer. This is because, the string object may keep the size of the string allocated in a different member of the class (depending on the implementation of course), and if the function alters the char buffer, interesting things might occur later on. If the function accepts a const char* instead of a char *, then at least you have some assurance that the function is not going to alter the contents. BTW string objects have a c_str() member function which returns the pointer to the char array of the object.
Last edited by Scorpions4ever : March 15th, 2003 at 07:15 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Can c++ strings be used as char buf[]? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|