I just started as a begginer in c++ coding and i got a doubt here
there is a pre-processor directive #include<string>
i had made a program including string variable without using it
can any one tell me is it neccesary to include it and what is its function?
the question might be stupid but i am a begginer :)
A #include statement makes the preprocessor take the contents of the file in the include statement, and inserts those contents into the code it's processing. In other words, it has the same effect as copying and pasting the entire contents of that included file into the source code.

Note that it doesn't actually change the source code file - but the output from the preprocessor will contain the contents of your source file, including the contents of the included files.

string is the name of the file containing the definition of the string type. Without having that definition included, the compiler has no way of knowing what string means in your source code.

But really, this stuff should be covered by any introduction to C++. If your questions are this basic, you're really better off just reading whatever books or tutorials you're using to learn C++.
Last edited on
Thanks MikeyBoy To clear out my doubt
Sometimes, another header might #include <string> for itself, but you should never rely on that. If you use something, #include the header for it.
thanks L B.
Topic archived. No new replies allowed.