cstring and string??
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...
<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.
<cmath> is the C++ version of the C library <math.h>
<cstdio> ... <stdio.h>
<cctype> ... <ctype.h>
And so on.
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
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
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
Popular Topics
Advertisement