Site for Tutorial C++ !

A

Alf P. Steinbach

* Ron Natalie:
Better than some, but still could use with some proofreading
by someone who actually KNOWS the language. Lots of mistakes
and misinformation in the first two chapters I read.

From the first chapter:

<quote>
The libraries are (also) called header files and, as computer files,
they have the extension ".h". An example would be house.h, or person.h.
As you see, they could have any name; when you start creating your own
libraries, you will give your files custom and recognizable names.

The first library we will be interested in is called iostream. It asks
the computer to display stuff on the monitor's screen.

To see how to put a library in your program, you put it at the beginning
of the file. Here is an example

include iostream.h
</quote>

It's difficult to know where to begin when the author's understanding is
so warped; I think I pass on this one...
 
F

Fabio

Alf P. Steinbach said:
* Ron Natalie:

From the first chapter:

<quote>
The libraries are (also) called header files and, as computer files,
they have the extension ".h". An example would be house.h, or person.h.
As you see, they could have any name; when you start creating your own
libraries, you will give your files custom and recognizable names.

The first library we will be interested in is called iostream. It asks
the computer to display stuff on the monitor's screen.

To see how to put a library in your program, you put it at the beginning
of the file. Here is an example

include iostream.h
</quote>

It's difficult to know where to begin when the author's understanding is
so warped; I think I pass on this one...
From lesson 12 - Dynamic Multi-Dimensional Arrays

int main()
{
int *pNumbers[2];

*pNumbers = new int[0]; // it allocates a vector of size 0
(*pNumbers)[0] = 31; // core dump
(*pNumbers)[1] = 29; // core dump
(*pNumbers)[2] = 31; // core dump
(*pNumbers)[3] = 30; // core dump
(*pNumbers)[4] = 31; // core dump
(*pNumbers)[5] = 30; // core dump

*(pNumbers+1) = new int[1]; // it allocates a vector of size 1
(*(pNumbers+1))[0] = 31; // we are lucky
(*(pNumbers+1))[1] = 31; // core dump
(*(pNumbers+1))[2] = 30; // core dump
(*(pNumbers+1))[3] = 31; // core dump
(*(pNumbers+1))[4] = 30; // core dump
(*(pNumbers+1))[5] = 31; // core dump

cout << "List of Numbers";
cout << "\n(*pNumbers)[0] = " << (*pNumbers)[0];
cout << "\n(*pNumbers)[1] = " << (*pNumbers)[1];
cout << "\n(*pNumbers)[2] = " << (*pNumbers)[2];
cout << "\n(*pNumbers)[3] = " << (*pNumbers)[3];
cout << "\n(*pNumbers)[4] = " << (*pNumbers)[4];
cout << "\n(*pNumbers)[5] = " << (*pNumbers)[5] << endl;

cout << "\n(*(pNumbers+1))[0] = " << (*(pNumbers+1))[0];
cout << "\n(*(pNumbers+1))[1] = " << (*(pNumbers+1))[1];
cout << "\n(*(pNumbers+1))[2] = " << (*(pNumbers+1))[2];
cout << "\n(*(pNumbers+1))[3] = " << (*(pNumbers+1))[3];
cout << "\n(*(pNumbers+1))[4] = " << (*(pNumbers+1))[4];
cout << "\n(*(pNumbers+1))[5] = " << (*(pNumbers+1))[5] << endl;

delete [] *pNumbers;
delete [] *(pNumbers+1);

return 0;
}

Fabio
Italy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top