what is the difference between string.h and cstring?

X

Xiaoshen Li

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

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xiaoshen said:
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-----
 
K

Keith Thompson

Xiaoshen Li said:
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).
 
D

Dominik Wallner

Xiaoshen said:
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
 
D

Default User

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
 
M

Michael Mair

Dominik said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top