cstring and string??

Started by
4 comments, last by pulpfist 17 years, 10 months ago
I'm just trying to understand the differences of these two headers. From what I understand, <cstring> is the c++ verions of <string>. Is this right? and I'm guessing this goes for all the others like <cmath> and <ctime> etc...
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
<cstring> is the C++ version of the C library <string.h> (not to be confused with <string> which contains the C++ std::string class)
<cmath> is the C++ version of the C library <math.h>
<cstdio> ... <stdio.h>
<cctype> ... <ctype.h>

And so on.
"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
okay, thanks, but whats the difference between <cstring> and <string>?
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by MikeTacular
okay, thanks, but whats the difference between <cstring> and <string>?


string is the header for the new string class introduced in C++.
cstring is the header which contains all C's string (char*, not std::basic_string<>) manipulation functions, like strcpy.
Just to elaborate a bit ...

a c string is a zero-terminated series of characters.
When you see:

const char* cstr;
or
char* cstr;

then cstr points to the start of such a series.
The series ends when a '\0' character is reached.
There are some functions that can be used to work with such character series like the strcpy function that CTar mentioned.

Now that C++ is object oriented ... how about putting such functions into a class?
A c++ string is a class from the STL (standard template library) that comes with some functions for string manipulation.
Internally it works with simple representations as well.

Here's a thread about char* and std::string:
Gamedev thread
Writing errors since 10/25/2003 2:25:56 AM
Quote:
okay, thanks, but whats the difference between <cstring> and <string>?

Just to elaborate some more...

The difference is, in short, that it is two entirely different libraries.

The new standard library scheme can be a bit confusing:

<string.h> --- The good old string library inherited from the C language.
<cstring> --- The good old string library inherited from the C language (New implementation. Belongs to the std namespace).
<string> --- The new string library that comes with C++. Has nothing to do with the other two

This topic is closed to new replies.

Advertisement