473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

what is the difference between string.h and cstring?

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
6 11137
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
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
-----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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: YinTat | last post by:
Hi, I learned C++ recently and I made a string class. A code example is this: class CString { public: inline CString(const char *rhs) { m_size = strlen(rhs);
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
2
by: Hai Ly Hoang [MT00KSTN] | last post by:
CString.FormatMessage and CString.Format has the same parameters and they seems to have to outcome. However, they coexist !. There must be some subtle different between they. Can you tell me the...
1
by: SteveK | last post by:
Trying to wrap an unmanaged class. Here is the function I'm trying to wrap: bool Init(PCSTR filename, PCSTR username, PCSTR password, PCSTR working); In my managed C++ class, I have a method...
3
by: Xiaoshen Li | last post by:
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...
2
by: Tio | last post by:
my code: if (new data ) { CString* pStr = (CString*)wParam; //data come with some com port (PostMessage) CString p2Str; //old string in edit box m_dataa.GetWindowText(p2Str);
28
by: federico_bertola | last post by:
Hi everybody! I have this function: int Scan(char String) { printf("%s", String); } it works but when I try to pass a dotted string o separetad with (" ", "_" , "-" ...ecc)
12
by: sas | last post by:
hi, i need that because the path functions for windows, like PathAppend and PathRemoveFileExt accept a writable zero terminated char*, but i didn't find that for std::string, with CString, i...
16
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName),...
4
Claus Mygind
by: Claus Mygind | last post by:
In my code I am sending a number of records via an ajax post method to the web-server for updating a table. I will parse the query string when it is received on the server side. But I am not sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.