A few questions about the compiler

This is a discussion on A few questions about the compiler within the C++ Programming forums, part of the General Programming Boards category; I'm just tooling around with C/C++ and I'd like to know what I need to do to "structure" my programs ...

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    A few questions about the compiler

    I'm just tooling around with C/C++ and I'd like to know what I need to do to "structure" my programs correctly. Say I want to create a project called Hello and a cpp file called Hello. How do I tell the compiler to include my Hello.cpp file in my Hello project? I assume this is how it's done in MSVS6. This is the way I've always done it in JBuilder. Thanks in advance on any replies.

  2. #2
    Unregistered
    Guest
    the short answer is to use a header file and #include it in your project.

    The example version might be:


    //create a header file
    //hello.h
    #ifndef HELLO_H
    #define HELLO_H
    #include <iostream.h> //or <iostream> depending on your compiler
    void display();
    #end;

    //create the cpp file for the header file
    //hello.cpp
    #include "hello.h" //or drop the .h if your compiler lets you
    void display()
    {
    cout << "hellow world" << endl;
    }

    //create the project cpp file
    //HELLO.cpp
    #include <iostream.h>
    #include "hello.h"
    int main()
    {
    display();
    return 0;
    }

    compile all three files.
    when you compile HELLO.cpp (depending on the switches you use) you will get an executable file (plus others).

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    To do it in MSVC, go to the fileview and right click on source files... add file to project

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    What I like to do is create a new project. You can call it Hello, then add the source files
    Then go to the "Project" menu and choose the "Add to Project" submenu. You can then choose "new" to create a new file, or choose "files" to add an existing file
    I usually create a new file called main.cpp for my projects

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Thanks for the help guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 09:47 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 08:42 AM
  4. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 06:44 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 08:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21