strings.h or string.h

S

shankha

Hi,
While using sting related functions in a c++ program which header file
one should use.
strings.h or string.h

thanks
shankha
 
V

Victor Bazarov

shankha said:
While using sting related functions in a c++ program which header file
one should use.
strings.h or string.h

Sting related functions would be found in 'bee.h' or 'wasp.h', and some
in 'police.h' :). If you need old C string functions, like 'strcpy' or
'strcat', include <string.h> or <cstring>. If you need the
'std::basic_string' class template (and its specialisations
'std::string' and 'std::wstring'), include <string>.

V
 
N

Neelesh

Hi,
While using sting related functions in a c++ program which header file
one should use.
strings.h or string.h

thanks
shankha

"string.h" is a C-header file that contains char* related function.
For example, all the good old functions like strlen() etc are declared
in <string.h>. The way to include this file in a c++ program is to say
#include <cstring>. On the other hand, <string> is a c++ header file
that contains the definition for c++ class string. The way to include
this header file in a c++ program is to say #include <string>. The
common thing between cstring and string is that both of these have all
the definitions enclosed in the namespace "std".
 
A

Alan Woodland

shankha said:
Hi,
While using sting related functions in a c++ program which header file
one should use.
strings.h or string.h
std::string is in <string>

Like the rest of the C headers, the header string.h is in <cstring>
(drop the .h, add a c at the beginning)

For new C++ code I would strongly recommend using std::string.

Alan
 
J

James Kanze

shankha wrote:
std::string is in <string>
Like the rest of the C headers, the header string.h is in
<cstring> (drop the .h, add a c at the beginning)

That's usually the case, but it isn't required---in fact, the
standard forbids it. The header <string.h> is in <string.h>;
all things said and said:
For new C++ code I would strongly recommend using std::string.

Yes. In practice, it's very rare to need either <string.h> or
<cstring>. (The only C headers you typically need are those
which contain functionality not otherwise available in C++:
<assert.h>, <stdlib.h> (for e.g. exit or abort), <time.h>, etc.
 

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

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top