Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import/ include string in cpp

I would like to use the string class. Should I also involve using namespace std;?

I thought #include <string> would be enough but in CLion when only one of these two (namespace or include) is absent, there are some errors.

What makes things more complicated, is that there is <string> or <strings.h>. What's the difference?

like image 439
Now.Zero Avatar asked May 13 '26 03:05

Now.Zero


1 Answers

<string> is C++ and provides the std::string class.

<string.h> is C (the C++ equivalent is <cstring>) and only provides functions to work on char*.

Don't use using namespace std; (see the C++ Core Guidelines).

like image 196
Matthieu Brucher Avatar answered May 14 '26 16:05

Matthieu Brucher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!