.h file extensions and compiler tool


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: .h file extensions and compiler tool

  1. #1
    Louise Guest

    .h file extensions and compiler tool


    I am new at this. I am trying to set up a header file in the C++ compiler
    -- very unsuccessfully so
    far. My code builds just fine, no errors or warnings. However, when I try
    to compile it, I get the
    message that there is "no compile tool associated with the .h file extension.
    I have trashed
    my code and project file and started new several times. I have uninstalled
    the Visual C++ compiler
    and then did a complete reinstall. Nothing helps. Here is the code that
    I am trying to compile:

    #include <iostream.h>
    class Cat
    public:
    Cat (int initialAge);
    ~Cat();
    int GetAge() const { return itsAge;}
    void SetAge (int age) { itsAge = age;}
    void Meow() const { cout << "Meow.\n";}
    private:
    int itsAge;
    };

    PLEASE DON'T suggest that I ad the #ifndef, #define, #endif to the code it
    does not work, I have
    already tried it. And again, it builds error and warning free, but it will
    not compile and I get the same
    message.

    I had someone else write this code on his computer and he did not have any
    trouble compiling it. I
    took what he wrote and tried to compile it on my computer and it would not
    compile!

    What am I doing wrong???? After less than a week into this stuff and I am
    ready to give up!

    Here are the steps that I have gone through to set up the header file:

    Using the Win32 Console Application, I set up a new (empty) project. Then
    I select "New"
    and "C++ header file", name it and tell it to add it to the project. Then
    I enter the code which
    builds without error. It will not compile!

    IS THERE ANYONE OUT THERE WHO CAN HELP ME??? I REALLY WOULD APPRECIATE IT!!!


  2. #2
    Dr_Muerte Guest

    Re: .h file extensions and compiler tool


    Prueba esto:
    #include <iostream> // <- sin .h
    class Cat
    { // <- inicio de clase
    public:
    Cat (int initialAge);
    ~Cat();
    int GetAge() const { return itsAge;}
    void SetAge (int age) { itsAge = age;}
    void Meow() const { cout << "Meow.\n";}
    private:
    int itsAge;
    };


    "Louise" <louise1007@mindspring.com> wrote:
    >
    >I am new at this. I am trying to set up a header file in the C++ compiler
    >-- very unsuccessfully so
    >far. My code builds just fine, no errors or warnings. However, when I

    try
    >to compile it, I get the
    >message that there is "no compile tool associated with the .h file extension.
    > I have trashed
    >my code and project file and started new several times. I have uninstalled
    >the Visual C++ compiler
    >and then did a complete reinstall. Nothing helps. Here is the code that
    >I am trying to compile:
    >
    >#include <iostream.h>
    > class Cat
    >public:
    > Cat (int initialAge);
    > ~Cat();
    > int GetAge() const { return itsAge;}
    > void SetAge (int age) { itsAge = age;}
    > void Meow() const { cout << "Meow.\n";}
    >private:
    > int itsAge;
    >};
    >
    >PLEASE DON'T suggest that I ad the #ifndef, #define, #endif to the code

    it
    >does not work, I have
    >already tried it. And again, it builds error and warning free, but it will
    >not compile and I get the same
    >message.
    >
    >I had someone else write this code on his computer and he did not have any
    >trouble compiling it. I
    >took what he wrote and tried to compile it on my computer and it would not
    >compile!
    >
    >What am I doing wrong???? After less than a week into this stuff and I

    am
    >ready to give up!
    >
    >Here are the steps that I have gone through to set up the header file:
    >
    >Using the Win32 Console Application, I set up a new (empty) project. Then
    >I select "New"
    >and "C++ header file", name it and tell it to add it to the project. Then
    >I enter the code which
    >builds without error. It will not compile!
    >
    >IS THERE ANYONE OUT THERE WHO CAN HELP ME??? I REALLY WOULD APPRECIATE

    IT!!!
    >



  3. #3
    jonnin Guest

    Re: .h file extensions and compiler tool


    Here is a terrible thing to do, but it may help tell me what is up.


    Combine the header and the code into one .cpp file. Include as .cpp. See
    if you can build into a .exe from this.

    and does the build give you an exe file? Yet compile does not work?

    Finally, turn off extension hiding in windows (if its on). ensure the .h
    has a .h extension.

    Answer this and we can narrow it down.


    "Louise" <louise1007@mindspring.com> wrote:
    >
    >I am new at this. I am trying to set up a header file in the C++ compiler
    >-- very unsuccessfully so
    >far. My code builds just fine, no errors or warnings. However, when I

    try
    >to compile it, I get the
    >message that there is "no compile tool associated with the .h file extension.
    > I have trashed
    >my code and project file and started new several times. I have uninstalled
    >the Visual C++ compiler
    >and then did a complete reinstall. Nothing helps. Here is the code that
    >I am trying to compile:
    >
    >#include <iostream.h>
    > class Cat
    >public:
    > Cat (int initialAge);
    > ~Cat();
    > int GetAge() const { return itsAge;}
    > void SetAge (int age) { itsAge = age;}
    > void Meow() const { cout << "Meow.\n";}
    >private:
    > int itsAge;
    >};
    >
    >PLEASE DON'T suggest that I ad the #ifndef, #define, #endif to the code

    it
    >does not work, I have
    >already tried it. And again, it builds error and warning free, but it will
    >not compile and I get the same
    >message.
    >
    >I had someone else write this code on his computer and he did not have any
    >trouble compiling it. I
    >took what he wrote and tried to compile it on my computer and it would not
    >compile!
    >
    >What am I doing wrong???? After less than a week into this stuff and I

    am
    >ready to give up!
    >
    >Here are the steps that I have gone through to set up the header file:
    >
    >Using the Win32 Console Application, I set up a new (empty) project. Then
    >I select "New"
    >and "C++ header file", name it and tell it to add it to the project. Then
    >I enter the code which
    >builds without error. It will not compile!
    >
    >IS THERE ANYONE OUT THERE WHO CAN HELP ME??? I REALLY WOULD APPRECIATE

    IT!!!
    >



  4. #4
    Danny Kalev Guest

    Re: .h file extensions and compiler tool

    in addition to the missing opening brace in class Cat, use <iostream>
    (with the appropriate using-declarations) not <iostream.h>, define the
    main() function, and create your project as a Console App because that's
    what it is.

    Danny

  5. #5
    Bopu Guest

    Re: .h file extensions and compiler tool


    if you are using <iostream> and not <iostream.h>
    then you have to use the following declaration :

    using namespace std;

    rgds
    bopu

    "Dr_Muerte" <Unknow@Unknow.pi> wrote:
    >
    >Prueba esto:
    >#include <iostream> // <- sin .h
    > class Cat
    >{ // <- inicio de clase
    >public:
    > Cat (int initialAge);
    > ~Cat();
    > int GetAge() const { return itsAge;}
    > void SetAge (int age) { itsAge = age;}
    > void Meow() const { cout << "Meow.\n";}
    >private:
    > int itsAge;
    >};
    >
    >
    >"Louise" <louise1007@mindspring.com> wrote:
    >>
    >>I am new at this. I am trying to set up a header file in the C++ compiler
    >>-- very unsuccessfully so
    >>far. My code builds just fine, no errors or warnings. However, when I

    >try
    >>to compile it, I get the
    >>message that there is "no compile tool associated with the .h file extension.
    >> I have trashed
    >>my code and project file and started new several times. I have uninstalled
    >>the Visual C++ compiler
    >>and then did a complete reinstall. Nothing helps. Here is the code that
    >>I am trying to compile:
    >>
    >>#include <iostream.h>
    >> class Cat
    >>public:
    >> Cat (int initialAge);
    >> ~Cat();
    >> int GetAge() const { return itsAge;}
    >> void SetAge (int age) { itsAge = age;}
    >> void Meow() const { cout << "Meow.\n";}
    >>private:
    >> int itsAge;
    >>};
    >>
    >>PLEASE DON'T suggest that I ad the #ifndef, #define, #endif to the code

    >it
    >>does not work, I have
    >>already tried it. And again, it builds error and warning free, but it

    will
    >>not compile and I get the same
    >>message.
    >>
    >>I had someone else write this code on his computer and he did not have

    any
    >>trouble compiling it. I
    >>took what he wrote and tried to compile it on my computer and it would

    not
    >>compile!
    >>
    >>What am I doing wrong???? After less than a week into this stuff and I

    >am
    >>ready to give up!
    >>
    >>Here are the steps that I have gone through to set up the header file:
    >>
    >>Using the Win32 Console Application, I set up a new (empty) project. Then
    >>I select "New"
    >>and "C++ header file", name it and tell it to add it to the project. Then
    >>I enter the code which
    >>builds without error. It will not compile!
    >>
    >>IS THERE ANYONE OUT THERE WHO CAN HELP ME??? I REALLY WOULD APPRECIATE

    >IT!!!
    >>

    >



  6. #6
    Kristoffer Edvinsson Guest

    Re: .h file extensions and compiler tool


    "Louise" <louise1007@mindspring.com> wrote:
    >
    >I am new at this. I am trying to set up a header file in the C++ compiler
    >-- very unsuccessfully so
    >far. My code builds just fine, no errors or warnings. However, when I

    try
    >to compile it, I get the
    >message that there is "no compile tool associated with the .h file extension.
    > I have trashed
    >my code and project file and started new several times. I have uninstalled
    >the Visual C++ compiler
    >and then did a complete reinstall. Nothing helps. Here is the code that
    >I am trying to compile:
    >
    >#include <iostream.h>
    > class Cat
    >public:
    > Cat (int initialAge);
    > ~Cat();
    > int GetAge() const { return itsAge;}
    > void SetAge (int age) { itsAge = age;}
    > void Meow() const { cout << "Meow.\n";}
    >private:
    > int itsAge;
    >};
    >
    >PLEASE DON'T suggest that I ad the #ifndef, #define, #endif to the code

    it
    >does not work, I have
    >already tried it. And again, it builds error and warning free, but it will
    >not compile and I get the same
    >message.
    >
    >I had someone else write this code on his computer and he did not have any
    >trouble compiling it. I
    >took what he wrote and tried to compile it on my computer and it would not
    >compile!
    >
    >What am I doing wrong???? After less than a week into this stuff and I

    am
    >ready to give up!
    >
    >Here are the steps that I have gone through to set up the header file:
    >
    >Using the Win32 Console Application, I set up a new (empty) project. Then
    >I select "New"
    >and "C++ header file", name it and tell it to add it to the project. Then
    >I enter the code which
    >builds without error. It will not compile!
    >
    >IS THERE ANYONE OUT THERE WHO CAN HELP ME??? I REALLY WOULD APPRECIATE

    IT!!!
    >


    Hi Louise!

    The thing is, you can never compile a .h file, at least not with any version
    of VC++. What happens when you choose to build your project is that the compiler
    compiles your source (.cpp) files, thus including AND compiling the header
    files that are included in your source files, producing object (.obj) files
    that are linked together to produce an executable file. This of course assumes
    that you have at least one source file with a complete main() function. Otherwise,
    I can't think of any other error than the previously mentioned 'missing opening
    curly brace in class declaration' suggestion to what's wrong. But that doesn't
    quite seem to be the source of the error either.

    Hope this helps
    /Kristoffer


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center