I don't get what's preprocessor.

I know what it is,But in all books it's just not typpen wich preprocessors use for kinds of codes.
Try this - it might clarify a few things for you :)
http://cplusplus.com/doc/tutorial/preprocessor/
When you submit a file to be compiled, the preprocessor is run over the code first.

All code that starts with # are handled by the preprocessor.

So when you write:
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "hello world" << std::endl;
    return 0;
}


#include <iostream> is a command to the preprocessor. It causes the proprocessor to look for file iostream and read its content in.

The compiler doesn't see the #include <iostream> , instead it sees the content of file iostream followed by the remainder of the file.

You can run the preprocessor and take a look at its output.

If you tell me what compiler you are using I may be able to instruct you on how to generate and view the preprocessor output.
@kbw: well i am using gcc compiler, how can i be able to view preprocessor output?
The preprocessor is traditionally named "cpp". That is the case with the GCC as well. For information on how to use it, type something like:

    cpp --help |less
or
    cpp --help |more

at the command line.

Hope this helps.
Put my program above into x.cpp.
Type:
g++ -C -E x.cpp
Topic archived. No new replies allowed.