473,378 Members | 1,209 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,378 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 11128
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.