RE: [Dev-C++] [OT] C++ string vs char *
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: James G. <Jam...@Cl...> - 2001-01-02 13:53:54
|
C++ Strings have a lot of the functionality of the str... type functions built into the classes. If you need to pass a char* to a function you can use c_str() which returns a char*. Best to read the doc's. There's: append - to append a char* or string. c_str - to return the underlying string as a char*. find_fist_of - to find the first occurrence of a string. resize - to allocate the memory for a string. + - add two strings together. != == > < etc. - comparison. See the string header file or docs for class members. Regards, James. -----Original Message----- From: Ramana Kumar [mailto:ra...@my...] Sent: Saturday, December 30, 2000 8:56 AM To: dev...@li... Subject: RE: [Dev-C++] [OT] C++ string vs char * I'm not too good with strings, but based on your e-mail, I would go for creating a simple string class. C++ strings become a pain depending on the things you do because they aren't compatible with char[]s and vice versa (I'm writing a game that takes in a string containing a command in English and acts accordingly, i.e. "Open door" opens the door). Using char*'s/char[]s gives you good control. I don't know what you mean by bloat/efficiency, but basically, from what I understand, I think the char*s will give more "efficiency?". The only problem with the char*s is, as you said you have to do your memory management but also some useful functions in string.h (I think) don't work on them. If some of what I'm saying is complete poppycock, I do apologise, I am going by experience, not by facts from the ISO C++ "set of rules". So as I said, I would take option b. Ramana -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of bis...@bt... Sent: Friday, December 29, 2000 9:05 PM To: dev...@li... Subject: [Dev-C++] [OT] C++ string vs char * Hi all I'm writing a small application using G++ - this one has a lot of string manipulation (It is a doxygen-like auto documentation system for a propreitory language). I seem to have three options: a) Use char *s and do my own memory management. b) Roll by own lightweight string class c) Use the C++ string class Can anyone tell me how good is the string class in terms of bloat/efficiency compared to char * ? Is (b) a viable option if what I want is basically char * with inbuild memory management ? Also, should I use (io|f|str)string ? How much of a bloat/efficiency concern is that compared to (f|s)printf/write/read and friends ? I don't plan to use the STL stuff. Thanks in advance. Biswa. _______________________________________________ Dev-cpp-users mailing list Dev...@li... http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users _______________________________________________ Dev-cpp-users mailing list Dev...@li... http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This electronic message and any attachment is intended to be read by the named addressee(s) only. Any other recipient should be aware that its contents may be legally privileged and/or confidential and that its use, disclosure, copying or distribution may be unlawful. Unless you are a named addressee, please delete this message Whilst C. & J. Clark International Limited has taken steps to prevent the transmission of computer viruses with electronic mail, responsibility for screening incoming messages and the risk of such transmission and its consequences lies with the recipient. C. & J. Clark International Limited Registered in England and Wales Company No. 141015 Registered Office: 40 High Street, Street, Somerset BA16 0YA Telephone: +44 (0) 1458 443131 Fax: +44 (0) 1458 447547 |