By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

what is the difference between string.h and cstring?

P: n/a
Dear All,

I saw some people using
#include <string.h>

some people using
#include <cstring>

What is the difference between the two? I can find the file string.h at
/usr/include. I don't know if cstring is a file and if so, where to find it.

It seems that there are also other similar things, like:
#include <math.h>

#include <cmath> (?? I am not really sure.)

Thank you very much.

Dec 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Xiaoshen Li <xl**@gmu.edu> writes:
I saw some people using
#include <string.h>

some people using
#include <cstring>

What is the difference between the two? I can find the file string.h
at /usr/include. I don't know if cstring is a file and if so, where to
find it.


<string.h> is C; <cstring> is C++.

I *think* both forms are legal in C++, but I don't know the details;
try comp.lang.c++ (but check their FAQ first).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 16 '05 #2

P: n/a
Xiaoshen Li wrote:
Dear All,

I saw some people using
#include <string.h>
This is the standard C header.
some people using
#include <cstring>
This is a C++ header and has no defined meaning in C.
What is the difference between the two?


See above.
Dec 16 '05 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xiaoshen Li wrote:
Dear All,

I saw some people using
#include <string.h>
Then, they were probably writing programs in the C programming language
some people using
#include <cstring>
And, these people were probably writing programs in the C++ programming language.
What is the difference between the two?


One (string.h) is an include file for C, and is on-topic in comp.lang.c

The other (cstring) presumably is an analogous file for C++, and is off-topic in
comp.lang.c

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDoxiiagVFX4UWr64RAszWAKDmKo3/8RFyXnRalyld569yeCkbKACgzU0A
p1ZmpiSpXfB7KgF0ae1qzPI=
=w28L
-----END PGP SIGNATURE-----
Dec 16 '05 #4

P: n/a
Xiaoshen Li wrote:
Dear All,

I saw some people using
#include <string.h>

some people using
#include <cstring>

What is the difference between the two? I can find the file string.h at
/usr/include. I don't know if cstring is a file and if so, where to find
it.

It seems that there are also other similar things, like:
#include <math.h>

#include <cmath> (?? I am not really sure.)

Thank you very much.


Yes, <xxx.h> is the C header (which also works for C++, though), and
<cxxx> is the corresponding C++ header file; the difference between
those both is that all the definitions of <cxxx> are in the C++
namespace std (like the STL), whereas <xxx.h> defines no namespace at all.

Regards,
Dominik Wallner
Dec 16 '05 #5

P: n/a
Keith Thompson wrote:

<string.h> is C; <cstring> is C++.

I think both forms are legal in C++, but I don't know the details;
try comp.lang.c++ (but check their FAQ first).


<OT>

<string.h> is standard but deprecated in C++.

</OT>

Brian
Dec 16 '05 #6

P: n/a
Dominik Wallner wrote:
Xiaoshen Li wrote:
Dear All,

I saw some people using
#include <string.h>

some people using
#include <cstring>

What is the difference between the two? I can find the file string.h
at /usr/include. I don't know if cstring is a file and if so, where to
find it.

It seems that there are also other similar things, like:
#include <math.h>

#include <cmath> (?? I am not really sure.)


Yes, <xxx.h> is the C header (which also works for C++, though), and
<cxxx> is the corresponding C++ header file; the difference between
those both is that all the definitions of <cxxx> are in the C++
namespace std (like the STL), whereas <xxx.h> defines no namespace at all.


Please stay on topic; if you give off-topic information, there
may be no one to correct potential errors. In this case, you omitted
that <xxx.h> is deprecated since the 1998 C++ standard -- this may be
helpful for the OP when deciding which variant to use in C++.
Rather direct off-topic requests to the appropriate newsgroup.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Dec 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.