• Advertisement
Sign in to follow this  

cstring and string??

This topic is 4253 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
okay, thanks, but whats the difference between <cstring> and <string>?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement