quote:
Original post by vaneger
the group im coding with are all newbies so i cant use pointers or classes or alot of stuff so im working with what i can use, how should i code the struct character = operator? also how can i code a char array copier?
That's an even greater incentive to try and do things the correct way. Far too many 'newbies' stubbornly reject the use of the standerd classes (common use of the std::string class is intuitive : it does exactly what you expect it to do), and end up learning a stunted version of the language. I urge you to learn C++, not "C with classes".
Case in point, you say you can't use pointers a lot. Well, C strings involve
a lot of pointers, null-terminators and such technicalities. std::string takes care of that for you. If they're not ready to deal with classes, you can gloss over it.
Now, to answer your question, the char array copier is named strcpy( destination, source );. With a std::string you don't have anything to do, there already is an assignment operator implemented and you can also directly assign a C-string to a std::string. To copy a std::string into a C char array, you do str.copy( array, array_length );.
Edit:
smart_idiot: Not at global scope, and #include <cstring> instead of <string.h>.
Documents [
GDNet |
MSDN |
STL |
OpenGL |
Formats |
RTFM |
Asking Smart Questions ]
C++ Stuff [
MinGW |
Loki |
SDL |
Boost. |
STLport |
FLTK |
ACCU Recommended Books ]
[edited by - Fruny on October 12, 2002 2:53:23 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan