Dear experts,
according to the standard, manipulators like noskipws are declared in
the header ios ([lib.iostreams.b ase]). But when I look at code that is
around, I usually see #include<iomani pbeing used. What is the correct
include, and why?
Thanks in advance for your time!
Best regards,
Bernd. 6 5473
On Nov 17, 11:20 am, Bernd Gaertner <gaert...@inf.e thz.chwrote:
Dear experts,
according to the standard, manipulators like noskipws are declared in
the header ios ([lib.iostreams.b ase]). But when I look at code that is
around, I usually see #include<iomani pbeing used. What is the correct
include, and why?
Thanks in advance for your time!
Best regards,
Bernd.
The header <iomaniptypical ly has member functions resetiosflags,
setiosflags, setbase, setfill, setprecision and setw. So it all
depends what you are doing.
Assuming you are using std::cout by including <iostream>, and since
iostream derives from istream/ostream which derive from ios (a diamond
hierarchy), noskipws doesn't need an include <iomanipunles s you plan
to use the set/reset members mentioned above.
You probably saw example code with include <iomanipmainl y because
the subject at hand was manipulation of streams.
On Nov 17, 5:20 pm, Bernd Gaertner <gaert...@inf.e thz.chwrote:
according to the standard, manipulators like noskipws are
declared in the header ios ([lib.iostreams.b ase]). But when I
look at code that is around, I usually see #include<iomani p>
being used. What is the correct include, and why?
It's rather arbitrary from a user point of view, but
manipulators which require an argument are declared in
<iomanip>, and those that don't are declared in <ios>. (There
are also a few, like endl, which only work on an ostream, and
are declared in <ostream>.) The reason behind this distinction
is mainly one of implementation; a manipulator which takes an
argument requires an additional type, which must be defined; if
you only include <ios>, you don't get a definition these types.
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Salt_Peter wrote:
Assuming you are using std::cout by including <iostream>, and since
iostream derives from istream/ostream which derive from ios (a diamond
hierarchy), noskipws doesn't need an include <iomanipunles s you plan
to use the set/reset members mentioned above.
I'm doing std::cin >std::noskipw s, and I ran across a platform where
#include<iostre amdoesn't suffice to do this. With an additional
#include<iosit worked. But according to what you write above, ios
should be included with iostream, meaning that the platform is buggy. Or
is it not allowed to infer this from the aforementioned diamond hierarchy?
Thanks,
Bernd.
James Kanze wrote:
It's rather arbitrary from a user point of view, but
manipulators which require an argument are declared in
<iomanip>, and those that don't are declared in <ios>.
Thanks. This seems to mean that for example the following code (you find
many similar things on the web) actually uses the wrong include:
#include <iostream>
#include <iomanip // for noskipws - (no skip whitespace)
char s;
int main()
{
std::cin >std::noskipw s;
while (std::cin >s)
{
std::cout << s;
}
return 0;
}
Best,
Bernd.
Bernd Gaertner wrote:
Salt_Peter wrote:
>Assuming you are using std::cout by including <iostream>, and since iostream derives from istream/ostream which derive from ios (a diamond hierarchy), noskipws doesn't need an include <iomanip> unless you plan to use the set/reset members mentioned above.
I'm doing std::cin >std::noskipw s, and I ran across a platform
where #include<iostre amdoesn't suffice to do this. With an
additional #include<iosit worked. But according to what you write
above, ios should be included with iostream, meaning that the
platform is buggy. Or is it not allowed to infer this from the
aforementioned diamond hierarchy?
The current standard does not specify which headers should be included
by <iostream>, so it is not a bug. Technically it is enough to include
<iosfwdto be able to declare (but not define) the streams.
Bo Persson
On Nov 18, 6:29*pm, Bernd Gaertner <gaert...@inf.e thz.chwrote:
James Kanze wrote:
It's rather arbitrary from a user point of view, but
manipulators which require an argument are declared in
<iomanip>, and those that don't are declared in <ios>.
Thanks. This seems to mean that for example the following code
(you find many similar things on the web) actually uses the
wrong include:
#include <iostream>
#include <iomanip* *// for noskipws - (no skip whitespace)
char s;
int main()
{
* * * * std::cin >std::noskipw s;
* * * * while (std::cin >s)
* * * * {
* * * * * * * * std::cout << s;
* * * * }
* * * * return 0;
}
Well, the comment is wrong, and the include of <iomanipisn't
necessary here. But it doesn't hurt, and I can imagine some
house rules just saying to include it anytime you use a
manipulator, rather than having the developers have to learn the
detailed rule; it doesn't hurt. (Of course, <ioswill be
included indirectly by <iostream>, so there's no risk of the
manipulator not being defined.)
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: liaoo |
last post by:
Dear all,
I have a question about using cout<<...
In standard C, I can use printf("%x",...) to print "hex" number. But in
Watcom C++, when using cout<<, I got the "decimal" representation !
Ex. a = 0x80000004
if ( using printf("%x",a) ) then I got "80000004" on screen
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |