ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What is the difference between:
#include <string>, #include <string.h>, #include <String.h>.
I'm so confused about C++ string. Which one am I suppose to use in C++.
Can anybody just give description on how to get this to work, In some files #include <string.h> works for me fine, and in other files I had to put #include <string>. Which one is right for C++?
also i think the difference in String.h and string.h may be none.. i am not at home to try it, but in devcpp i get no errors when i do something like
#include <IoStReAm>
so maybe the case is not mattering..
I have not used String.h that is any different that i know of..
string.h is not deprecated.. it is the C string lib.. if you use
string.h is(!) deprecated (at least for C++, I had already added this extra-piece in my earlier post), it is not part of C++ standard any more (once it was) -> so deprecated. But the problem is solved anyway, so who cares... ;-)
Thanks xhi,
One more question, sorry i'm kinda new in C++. whenever you include in c++, you don't add .h, right?
and if I want to include something from C, do I add extern "C" {#include <something_in_C.h>}?
well not everything, but the new version of the std lib you dont.. so anything like iostream, string, fstream, etc... you do not..
with header files you create you will.. and other files that are not standard like for example from a graphics lib you are using or somthing like that..
i cannot help with the extern C as I have read the definition before, but have not found a use for it.. so I do not have the complete understanding of it..
string.h is(!) deprecated (at least for C++, I had already added this extra-piece in my earlier post), it is not part of C++ standard any more (once it was) -> so deprecated. But the problem is solved anyway, so who cares... ;-)
the way you put it is not correct
Quote:
Originally Posted by Flesym
this is deprecated for C++...
Code:
#include <string.h>
...so simply use always
Code:
#include <string>
string.h and string are not and were not the same files..
string.h is deprecated for cstring not string
<edit> cstring and string.h contain the same functionality, just a namespace diff </edit>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.