Great book - I like the way that unlike other books, AC++ explains as
much as possible about every piece of code discussed, so I'm not left
thinking, "well...OK. .. I get line 12, but I wonder what the rest of
it means...".
Still, I have some questions, that are frustrating me:-
Grateful for any comments.
1. What is the difference between
#include <iostream> // (or any include file) which is used in this
book, and
#include <iostream.h> // which is used in other books I've looked at.
2. Does the absence of the '.h' have something to do with the need
for std:: before cout ?
3. std, the book esplains, is a namesace. But what is a namespace,
particularly in this case?. Is it something I can open and look at in
Notepad?
............... ............... .......
I'm up to chapter 4, and relativaly comfortable with it, but these
early questions are still nagging me.
Thanks 39 2410
TonyJeffs skrev: Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK. .. I get line 12, but I wonder what the rest of it means...".
Still, I have some questions, that are frustrating me:- Grateful for any comments.
1. What is the difference between #include <iostream> // (or any include file) which is used in this book, and #include <iostream.h> // which is used in other books I've looked at.
#include <iostream> is the suggested way of including files
in c++ (at least for standard libraries)
#include <iostream.h> is just about the same, except most
compilers will give you a warning telling you its deprecated.
When writing your own header files - select what suits you the best.
Personally, I like .h or .hpp 2. Does the absence of the '.h' have something to do with the need for std:: before cout ?
No.
3. std, the book esplains, is a namesace. But what is a namespace, particularly in this case?. Is it something I can open and look at in Notepad?
A namespace is a concept of grouping things - like functions, classes
and constants - that belong together.
Using namespaces makes your code more readable and more easily
maintained.
The standard libraries, such as iostream, use a namespace called
std - that's why you see things like 'std::cout << "blah" << std::endl;'
or 'using namespace std;'
Google it.
-- Pelle
"TonyJeffs" <to*******@aol. com> wrote in message Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left
I haven't read anyone saying otherwise about the book :-)
thinking, "well...OK. .. I get line 12, but I wonder what the rest of it means...".
Still, I have some questions, that are frustrating me:- Grateful for any comments.
1. What is the difference between #include <iostream> // (or any include file) which is used in this book, and #include <iostream.h> // which is used in other books I've looked at.
The other books you have looked at are outdated. Standard headers are
extensionless.
2. Does the absence of the '.h' have something to do with the need for std:: before cout ?
Yes, everything inside standard headers is wrapped inside std namespace. So
cout needs to be addressed as std::cout.
3. std, the book esplains, is a namesace. But what is a namespace, particularly in this case?. Is it something I can open and look at in Notepad?
What have namespaces to do with Notepad ?? Namespaces allow us to group a
set of global classes, objects and/or functions under a name. This helps in
avoiding name conflicts, and redefinition errors.
namespace a {
int i; // OK
}
namespace b {
int i; // OK
}
Sharad
"Pelle Beckman" <he******@chell o.se> wrote in message 1. What is the difference between #include <iostream> // (or any include file) which is used in this book, and #include <iostream.h> // which is used in other books I've looked at. #include <iostream> is the suggested way of including files
Not suggested, but correct way of including files in ISO C++.
in c++ (at least for standard libraries) #include <iostream.h> is just about the same, except most compilers will give you a warning telling you its deprecated. When writing your own header files - select what suits you the best. Personally, I like .h or .hpp
2. Does the absence of the '.h' have something to do with the need for std:: before cout ?
No.
Why ? 3. std, the book esplains, is a namesace. But what is a namespace, particularly in this case?. Is it something I can open and look at in Notepad? A namespace is a concept of grouping things - like functions, classes and constants - that belong together. Using namespaces makes your code more readable and more easily maintained.
Is that the only goal of namespaces ?
Sharad
"TonyJeffs" <to*******@aol. com> wrote in message
news:8e******** *************** ***@posting.goo gle.com... 1. What is the difference between #include <iostream> // (or any include file) which is used in this book, and #include <iostream.h> // which is used in other books I've looked at.
<iostream.h> is not part of standard C++, although many implementations
include it for compatibility with earlier usage.
2. Does the absence of the '.h' have something to do with the need for std:: before cout ?
Yes.
3. std, the book esplains, is a namesace. But what is a namespace, particularly in this case?. Is it something I can open and look at in Notepad?
A namespace is something that is part of the C++ language. It is not a data
structure that you can access directly. A namespace has a name and contains
a (possibly empty) collection of names. When you want to use one of the
names that a namespace contains, you can refer to it as x::y, where x is the
name of the namespace and y is the name that it contains.
So when you say
#include <vector>
the compiler puts the name "vector" into the namespace named "std", after
which you can refer to std::vector. Alternatively, by saying "using
std::vector;" you can cause the name "vector" to be brought into the global
namespace, after which you can refer to vector without the "std::" in front
of it.
TonyJeffs wrote: Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK. .. I get line 12, but I wonder what the rest of it means...".
Still, I have some questions, that are frustrating me:- Grateful for any comments.
1. What is the difference between #include <iostream> // (or any include file) which is used in this
This is valid C++.
book, and #include <iostream.h> // which is used in other books I've looked at.
This is not valid C++. It was used before the final C++ standard.
2. Does the absence of the '.h' have something to do with the need for std:: before cout ?
No.
3. std, the book esplains, is a namesace. But what is a namespace, particularly in this case?. Is it something I can open and look at in Notepad?
We can say that namespace is a scope for grouping facilities.
--
Ioannis Vranos http://www23.brinkster.com/noicys
* Pelle Beckman: TonyJeffs skrev: Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK. .. I get line 12, but I wonder what the rest of it means...".
Still, I have some questions, that are frustrating me:- Grateful for any comments.
1. What is the difference between #include <iostream> // (or any include file) which is used in this book, and #include <iostream.h> // which is used in other books I've looked at. #include <iostream> is the suggested way of including files in c++ (at least for standard libraries)
No suggestion.
<iostream> is a standard header.
<iostream.h> is not, and is only available with certain compilers.
#include <iostream.h> is just about the same, except most compilers will give you a warning telling you its deprecated.
_No_ compiler will tell you that.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Thanks for all the advice. As well as helping me know what's going on,
any interaction on the topic will be a big help in keeping me going
and on track!
My next Question (sec 4.1.2 in case anyone wants to look at the
book):
const vector<double>& hw =homework)
I follow that hw is a synonym for homework.
But it seems to me that '&' does not mean 'the address of' in this
case. It means something a bit different. Am I correct? What phrase
could I use to explain the &?
Does this & mean 'by reference'?
(You'll see my brain's a bit cluttered with things I've half read and
half understood in the past!!)
Thanks again,
Tony
tony_jeffs wrote: My next Question (sec 4.1.2 in case anyone wants to look at the book):
const vector<double>& hw =homework)
I follow that hw is a synonym for homework. But it seems to me that '&' does not mean 'the address of' in this case. It means something a bit different. Am I correct? What phrase could I use to explain the &? Does this & mean 'by reference'?
Not quite. In this context & means that hw is a reference. Look up
references in your book.
To quote another great C++ book (C++ Primer, Lippman & Lajoie): "A
reference, sometimes referred to as an alias, serves as an alternative
name for an object. A reference allows for the indirect manipulation of
an object in a manner similar to the use of a pointer but without
requiring use of pointer syntax".
But what does that mean in real life? Lets look at an example:
Using a pointer:
void GetName(std::st ring* name)
{
// Check if name is valid
if(!name)
{
throw std::runtime_er ror("Invalid name pointer");
}
// Do something to get a name
...
*name = "something" ;
}
Using a reference:
void GetName(std::st ring& name)
{
// Do something to get a name
...
name = "something" ;
}
By using a reference parameter instead of a pointer parameter, the
compiler will make sure that you get a valid object you can use
(although there are pitfalls!). If you use a pointer you need to do the
checking by yourself.
There are other ways of using a reference type. Compare these two functions:
void OutputName(std: :string name)
{
....
}
void OutputName(cons t std::string& name)
{
....
}
What's the difference? Calling the first function will pass a copy of
the name (which of course means that a copy will be made). Calling the
second function will only pass a reference to the name (much cheaper,
especially when dealing with long strings, vectors, etc.).
HTH.
--
Peter
Are you realy the guy who wrote those C++ books?
How is Bjarne? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joe Laughlin |
last post by:
On 6.2.3/115 of "Accelerated C++", there's this function:
double average(const vector<double>& v)
{
return accumulate(v.begin(), v.end(), 0.0) / v.size();
}
The author notes that it's important to use 0.0 in the function, as
accumulate uses the third argument's type as its return type.
|
by: blangela |
last post by:
I am currently teaching 2 part-time (one evening per week) C++ courses
using the Deitel & Deitel "C++ How To Program" text. Each course is 13
weeks in length, including time for labs and exams. In earlier posts
to this usenet site, people have recommended that I switch texts to
"Accelerated C++" by Koenig and Moo.
I have just recently received a desk copy of the text from the
publisher and I do believe that the approach taken by the...
|
by: Michael Bell |
last post by:
I did an the Open University course MT262. I got 3/4 the way through
it and only really came unstuck at classes.
Following the advice of many, on this list and elsewhere, and
impressed by their statement that students were writing substantial
programs within a day, I bought "Accelerated C++" by Koenig and Moo.
I find I just can't get on with it. I have started at the beginning,
and I just can't follow it. The first few chapters do...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |