Click to See Complete Forum and Search --> : #include
What is this line for? What is contained in it? Like, are there built functions?
#include <iostream.h>
And where is iostream.h located? Is it built into C++ or is it a separate file?
parksie
Oct 3rd, 2000, 06:09 PM
A header file contains definitions of function prototypes and various constants. The prototypes are for the compiler to do its type-checking, but if there's no matching .lib file, the linker whinges at you.
The iostream.h file contains input/output stream support, which is basically cout, cin, and that lot.
The header files are usually stored in a folder called "include" (surprisingly enough). Look under your VC folder, and it should be there.
Note the important distinction though:
#include <iostream.h>
// is not
#include "iostream.h"
If it's enclosed in angle-brackets, it begins searching for the include file in the system includes folder (mentioned earlier). If it's in quotes, it begins searching in the current source folder.
Say I make a file, do I need to include this .h files with it? And are these just the basics? There are many more out there on the C++ programming sites? And last thing (for now), you seem to be a C++ expert, parksie, how long did it take you to learn and what have you made in C++?
hitcgar
Oct 4th, 2000, 01:58 PM
You include any file that contains defs of classes, functions, constants etc. that you want to use in your app.
Here's how includes basically work:
Ex.
//in file my.h
#ifndef MY_H
#define MY_H
#include <windows.h>
#include <whatever.h>
// some function prototypes
char* getPath(char* fileName);
int addA_B(int a, int b);
// class prototype
class myClass : public
{
// ....
};
class automobile : public
{
//...full class definition...
};
// end my.h
#endif
Then in my.cpp you would include 'my.h' but not 'windows.h' etc.
because they were included in my.h and therefore will now
be in my.cpp - includes are accumulative.
So if you have another source file in your proj. you can do this:
#ifndef MY_H
#include <my.h>
#endif
which will ensure that you only include my.h if it hasn't already been included.
If you need to use some specific API for example a common control you would do
#include <commctrl> // don't need the .h in VC++
Anyway a lot more could be said.
have fun
parksie
Oct 4th, 2000, 02:03 PM
What you include depends on what you want to use. Basically, these are the standard ones you'll see the most. Note that some are part of the Standard C++ Library, and some are part of the Standard C Library. The C++ headers have no .h extension, although they're headers.
Standard C++ Library
--------------------------
iostream - Input/Output stream support
string - string class
vector - Dynamic arrays
Standard C Library
--------------------------
stdio.h - I/O
stdlib.h - Various useful functions
math.h - Maths functions
string.h - Functions to manipulate strings in char array form
The C functions can also be used from C++, too. Check in the documentation for each function to see which headers you need.
It took me about 5 years to get confident with C, and I've been using C++ for the past 2 years (7 years total).
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.