Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-14-2005, 01:10 PM   #1 (permalink)
soniw23
Registered User
 
soniw23's Avatar
 
Join Date: Aug 2005
Posts: 1
soniw23 is on a distinguished road
Arrow header files

Im new to programming and i want to know can you make your own header files in C or C++?

soniw23 is offline   Reply With Quote
Old 08-14-2005, 01:45 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
yes, a description is to be found here a closer use of it in contence, is to be found here.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-14-2005, 02:34 PM   #3 (permalink)
fp_unit
mike
 
Join Date: Jan 2005
Location: Ottawa, ON
Posts: 79
fp_unit is on a distinguished road
Code:
/* Filename: Simple.h */
/* These 2 lines below, and the final one at the bottom are recommended.
 * You should include them in all your header files so functions/data types
 * don't get defined (#included) twice.
 */
#ifndef YOUR_HEADER_NAME_DEFINED
#define YOUR_HEADER_NAME_DEFINED

/* put #defines, #includeds, const values, classes, 
 * typedefs and prototypes here */

#include <iostream>
#include <cstring>
using std::cout;
using std::strcpy;

class Simple
{
private:
   char * str_;

public:

    Simple(const char* str) { strcpy(str_, str); }
    char* getString() { return str_; }
    void print() const { cout << str_ << '\n'; }
};

#endif

Code:
/* Filename: main.cpp */
#include "Simple.h"

int main()
{
    Simple string1("I am a string!");
    string1.print();

    return 0;
}
If you're using Linux, make sure the two files are in the same directory and use g++ to compile:

Code:
[shell]$ g++ -o Simple main.cpp
[shell]$ ./Simple
I am a string!
[shell]$
fp_unit is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
warning cannot create pre compiled header: initialized data in header Nielszz Platform/API C++ 2 06-28-2005 01:06 PM
Including Header Files and their cpp counterparts Rafkin Standard C, C++ 5 02-06-2005 09:48 PM
to C or C++ cheawick Standard C, C++ 13 05-05-2004 04:45 PM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM


All times are GMT -8. The time now is 08:41 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting