Re: Borland C++BuilderX
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 03/02/04
- Next message: Simon.: "Re: [C] Working with disk files. *long post warning*"
- Previous message: Henri Schomäcker: "convert image-data in char* in binary mode into BSTR"
- In reply to: Malcolm Taylor: "Borland C++BuilderX"
- Next in thread: Chris \( Val \): "Re: Borland C++BuilderX"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 2 Mar 2004 11:07:08 +0000
In message <c21ie2$6hor$1@news3.infoave.net>, Malcolm Taylor
<mtaylor@malcolmtaylor.com> writes
>I am very new to C++ and would like information on the following example:
>
>"#include <iostream>
>#include "main.h"
>
>int main(int /*argc*/, char* /*argv*/[])
>{
> std::cout << "Hello world!" << std::endl;
> std::cout << "Please enter a character and press return:";
>
> std::cin.get();
>
> std::cout << "Goodbye world!" << std::endl;
> return 0;
>}"
>
>1. All of the books I have reviewed so far do not give information on std::
>What is this and where can I find a book that teaches this method?
OK here is what I tell my readers as they work through their first
program:
<quote>
C++ provides a sophisticated mechanism naming things. It is among the
most sophisticated that I have come across. It allows programmers to
provide information about where names are declared and the context that
adds to their meaning. This should not be a strange idea because we use
something like it in everyday conversation. When you hear an art teacher
talk about drawing a gun you do not expect that to be followed by firing
it. However if you hear a police officer use the same phrase, you would
be surprised if he then went on to describe the use of charcoal for the
purpose.
At this early stage in your programming I do not want to have to explain
the mechanisms for providing short names in context so I have provided
the full names for the things I am using from the C++ Standard Library
(those that start with std::) and my library (those that start with
fgw::). Names are important in programming and I will have a lot more to
say about them as we progress.
Mostly, programmers do not worry about the contents of header files,
they just include them where needed. Sometimes they will look in a
header file to make sure they know how the names being provided have
been spelt and the details they need for correct use.
</quote>
A few pages latter I introduce the mechanism for using short names:
<quote>
Did you get irritated by having to type in all those fgw:: prefixes to
names from my library? Well, even if you did not, I did. We can avoid
the need to add those prefixes by telling the compiler that we are using
a particular namespace (the context of a library). The required program
statement is:
using namespace fgw;
for my library and:
using namespace std;
for the C++ Standard Library.
You need to be careful that you only write those statements in your own
source code files and never place them in header files which will be
shared by other people (or even yourself). I will use this technique in
the rest of the source code that I provide but use the full name when I
need to identify which library a name belongs to.
You already use names like this. My friends call me ‘‘Francis’’
and only add ‘‘Glassborow’’ when they need to distinguish me
from some other Francis. C++ names work almost exactly the same way.
</quote>
That should give you the idea.
>2. Although it doesn't appear to be a huge deal, how does "#include
>"main.h"" differ from say "#include <main.h>"
And focusing on purpose [even though not a complete statement because
other implementation headers can be located with the <name> or <name.h>
(or any other extension you want to use if you insist on being
different) syntax] I write for the novice's first time experience:
<quote>
The next two lines of our program are instructions to the compiler to
tell it that it will need to look up information somewhere else. We call
these other places ‘‘header files’’ (I guess because they come
at the head of a file of source code). Header files generally have a .h
extension, except the ones that belong to Standard C++ which have no
extension (and are usually just called headers). A second difference is
that the names of the Standard C++ headers are placed in angle brackets
and the names of the others are placed in quotes. That matters: if you
get it wrong, the compiler may not be able to find the right files.
There is also a small issue of good style. Place the ordinary header
files first, in alphabetical order. Place the Standard C++ headers
afterwards, again in alphabetical order. The compiler will not care
about this but other human readers may.
The contents of the header files and headers will be copied into your
file on a temporary basis (we call this pre-processing). If you look at
the contents of a header file (you can find the ones for my library in
the fgw headers directory), they might look pretty strange. There is
nothing mysterious about them; they are like tables of contents for a
book except that a header file documents what can be found in a
corresponding C++ library or source code file. C++ library files (such
as libgdi32.a, which provides graphics support for Microsoft Windows,
and fgwlib.a, which contains the special support material I have written
for this book) have a .a extension in this IDE; C++ source code files
use a .cpp extension by convention. The compiler (the tool that
translates source code to object code) needs to know what the linker
(the tool that links, or joins together, your code with other code to
make a complete program or executable) can expect to find in other
object code files and libraries. Header files give the compiler this
essential information.
</quote>
I hope that helps a little.
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: Simon.: "Re: [C] Working with disk files. *long post warning*"
- Previous message: Henri Schomäcker: "convert image-data in char* in binary mode into BSTR"
- In reply to: Malcolm Taylor: "Borland C++BuilderX"
- Next in thread: Chris \( Val \): "Re: Borland C++BuilderX"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|