Headers

This is a discussion on Headers within the C++ Programming forums, part of the General Programming Boards category; Hey guys! It's all coming along nicely now. Much less confused than before, but still so so far from being ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    6

    Headers

    Hey guys!

    It's all coming along nicely now. Much less confused than before, but still so so far from being independent

    This morning I ran into a problem. I've tried to use headers because I love being able to create little pieces of code that create functions and orginize them correctly. But I'm doing something wrong.

    I have three files. One is my main project with int main() that includes the header, then there is a header which is a .h file declaring a function, and lastly a .cpp file to define what the function does.

    Code:
    #include <iostream.h>
    #include "Head.h"
    
    using namespace std;
    
    int main(){
    cout << "Testing. Next line is a function. \n";
    Function();    
    system("PAUSE");
    return 0;    
    }
    Code:
    void Function();
    Code:
    #include <iostream.h>
    
    using namespace std;
    
    void Function(){
               cout << "Testing... 1, 2, 3... It works!";
               }
    The problem is that it doesn't quite work. cout that should print the text in function Function isn't printing the text. So that sucks!

    Apart from that. Right now I have one header and one cpp file for every function I make. I assume I could just have one header called "SoundHandling" and have like 30 functions in there to handle sound(for example)?

    Also, right now my functions and headers are visible to anyone. Could I include them in my project, and then save the project as some encrypted executable? Like have a few cpp files with functions included in my project (In Dev-C++ under my main cpp file in the list on the left.) and a header as well. I hope I'm making sence

    Edit ------------
    Oh, and I assume that iostream is a header that includes alot of basic functions like cout. Does every computer have this file, or did it come with my compiler and must I include it as well?
    Apart from that. What is the .o file, and .win file. Should I include them as well when sharing my program with others?

  2. #2
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    >>The problem is that it doesn't quite work. cout that should print the text in function Function isn't printing the text. So that sucks!

    Worked fine for me. I copy/pasted the files into Dev-C++ and all I had to do was add #include <cstdlib> to the .cpp file that contained main() for the system("pause") command.

    >>I assume I could just have one header called "SoundHandling" and have like 30 functions in there to handle sound(for example)?

    yup.

    However, you don't have to include the headers in your project, just the appropriate .cpp files.

    [running a more serious risk of being wrong and raising the ire of more senior members of the board]

    >>save the project as some encrypted executable?
    Not neccesary. Someone using the program shouldn't be able to see the functions just by running the program.

    >>I assume that iostream is a header that includes alot of basic functions like cout
    Pretty much.

    >>Does every computer have this file, or did it come with my compiler
    If you didn't download it yourself, it came with the compiler.

    >>must I include it as well?
    Only if you want cout to work

    >>Should I include them as well when sharing my program with others?
    No need. Once you compile, Dev-C++ will create a stand-alone executable. That's all you need to share the program with others.

    [/running a more serious risk of being wrong and raising the ire of more senior members of the board (for now)]
    There is a difference between tedious and difficult.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    The problem is that it doesn't quite work. cout that should print the text in function Function isn't printing the text. So that sucks!
    When you post about a problem, you need to list the errors you are getting along with a comment in your code on the line the error is occurring.

    #include <iostream.h>
    It should be:

    #include <iostream>

    not:

    #include<iostream.h>

    Apart from that. Right now I have one header and one cpp file for every function I make. I assume I could just have one header called "SoundHandling" and have like 30 functions in there to handle sound(for example)?
    Yes, exactly. Having one function per .cpp file is not a very good way to organize your code.

    Also, right now my functions and headers are visible to anyone.
    How is that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 06-18-2005, 03:26 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-24-2004, 12:22 AM
  3. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04:49 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM

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