473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11160
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_Keit h) 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)

iD8DBQFDoxiiagV FX4UWr64RAszWAK DmKo3/8RFyXnRalyld569 yeCkbKACgzU0A
p1ZmpiSpXfB7KgF 0ae1qzPI=
=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
4733
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
3658
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
5229
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 difference ? Thank a lot
1
3839
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 like this: bool CSUSSWrapper::Init(String* filename, String* username, String* password, String* working) {
3
688
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 know if cstring is a file and if so, where to find it.
2
2804
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
2919
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
12411
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 usually use GetBuffer for that LPTSTR CString::GetBuffer( int nMinBufLength )
16
3424
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), _netguid(netguid) {}
4
3287
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 if I need to make each element in each record a unique name/identifier. Right now I was just trying to figure out what the query string looks like when it arrives at the server. I kind of see the errors of my ways, but would like some...
0
8139
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6064
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.