none
#include header not working

    Question

  • My problem is that I can't seem to understand  why sometimes when I create a new project in .cpp applications the header file #include dosent work, like it is not in blue color. I tried to see what am I doing different from the times it does work but can't figure it out . >?

    Thursday, October 31, 2013 4:30 AM

Answers

  • My problem is that I can't seem to understand  why sometimes when I create a new project in .cpp applications the header file #include dosent work, like it is not in blue color.

    First off, you obviously should state which compiler and version you're using.
    Features, bugs, etc. differ from product to product and version to version.
    Don't assume that one answer will apply to every product and every version of
    a given product.

    Is this in the Visual C++ IDE editor, or some other editor?

    Two things come to mind:

    (1) If you inadvertently put the #include within the range of a comment then it will
    become part of the comment.

    (2) The color - if any - given to a line such as #include <...> is part of the syntax
    coloring settings of the VC++/VS IDE editor. These are specific to files that have
    a specified extension. If an #include is put in a file that does't have one of the
    extensions specified in the settings (such as .c, .cpp, .h, etc.) then it won't have
    the associated color. For example, if you put an #include in a file which has an
    extension of .txt then it won't be colored.

    - Wayne

    Thursday, October 31, 2013 6:04 PM

All replies

  • Try adding #include "stdafx.h" first before including your header file. This is needed if the project is built with precompiled header which is the default setting while creating project on visual studio.

    Farnadis

    Thursday, October 31, 2013 7:24 AM
  • At all I'm not sure if you problem is only the syntax highlighting (blue #inlcude) or the include functionality itself. If it is the functionality itself, please post a piece of code.

    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    Thursday, October 31, 2013 7:37 AM
  • My problem is that I can't seem to understand  why sometimes when I create a new project in .cpp applications the header file #include dosent work, like it is not in blue color.

    First off, you obviously should state which compiler and version you're using.
    Features, bugs, etc. differ from product to product and version to version.
    Don't assume that one answer will apply to every product and every version of
    a given product.

    Is this in the Visual C++ IDE editor, or some other editor?

    Two things come to mind:

    (1) If you inadvertently put the #include within the range of a comment then it will
    become part of the comment.

    (2) The color - if any - given to a line such as #include <...> is part of the syntax
    coloring settings of the VC++/VS IDE editor. These are specific to files that have
    a specified extension. If an #include is put in a file that does't have one of the
    extensions specified in the settings (such as .c, .cpp, .h, etc.) then it won't have
    the associated color. For example, if you put an #include in a file which has an
    extension of .txt then it won't be colored.

    - Wayne

    Thursday, October 31, 2013 6:04 PM