473,772 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Requirements for <iostream>

In a discussion elsewhere, someone wrote:

#include <iostreamis not guaranteed to define std::cout, it
merely has to declare it as an extern object, and declarations
of extern objects do not require complete types. As far as I
understand, a implementation is free to use a certain amount
of compiler magic to be able to declare std::cout etc. without
defining basic_ostream.

Is this correct? If so, then it would mean that the following program
is invalid:

#include <iostream>
int main() { std::cout; }

I don't see how an extern definition can be provided but the type
be incomplete (unless it is a definition of an array of unknown size).

Secondly, section 27.3 of the standard (1998) says that <iostream>
must define:
extern ostream cout;

but says nothing else about ostream. Does this imply that std::ostream
must be declared at this point (ie. basic_ostream<m ust have been
declared, and typedef'd to ostream as well) ?

Mar 5 '07 #1
1 2054
Old Wolf wrote:
In a discussion elsewhere, someone wrote:

#include <iostreamis not guaranteed to define std::cout, it
merely has to declare it as an extern object, and declarations
of extern objects do not require complete types. As far as I
understand, a implementation is free to use a certain amount
of compiler magic to be able to declare std::cout etc. without
defining basic_ostream.

Is this correct? If so, then it would mean that the following program
is invalid:

#include <iostream>
int main() { std::cout; }
Probably. What does it do?
>
I don't see how an extern definition can be provided but the type
be incomplete (unless it is a definition of an array of unknown size).
We have the <iosfwdheader , that is intended to use where you need
declarations but not definitions.
>
Secondly, section 27.3 of the standard (1998) says that <iostream>
must define:
extern ostream cout;
Definitely

#include <iosfwd>

namespace std
{
extern ostream cout;
}

must be enough. Note that <iosfwdcontai ns the typedef for ostream.

If you want to use any of the operators on a stream, you have to include
<ostreamor <istreamas well. That's were operators << and >are defined
(most of them, anyway).
Bo Persson
Mar 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
89406
by: John Tiger | last post by:
Can anybody have idea about the difference between #include <iostream.h> and #include <iostream>. Is later one valid statement on any compiler. I tried compiling on MSVC second statement give compilation error as #include expect filename. Anu help would be appreciated. thanx, John
1
2469
by: Juergen Marsch | last post by:
Hi, writing files > 2G with standard library iostream classes results in "... file size limit exeeded." Compiling my program with "-D_FILE_OFFSET_BITS=64" doesn't make any difference. If you know a solution, please tell me. Thanks, Jürgen
9
2372
by: ai | last post by:
Hi , I have an application which has to read files of size few mba nd read them into array . Since i am using STL and std namespace to avoid the error error C2872: 'ifstream' : ambiguous symbol when i include <iostream.h> with std namespace and <List>
4
5939
by: aurgathor | last post by:
Howdy, What would be the equivalent of getch() using iostream? My current code is: cout << "\nPress <Enter> to continue..."; getch(); but <conio.h> is not kosher for the C++ class.
2
2164
by: Brett | last post by:
Hi, I'm compiling an old project under the 'new' visual studio 7.1.3088. I changed the line: #include <iostream.h> to #include <iostream> and now I get a stack of errors, some of which are:
9
6174
by: nichas | last post by:
I tried to use #include<iostream> in visual C++ compiler but then it didnt work but i see this is the way it is being mentioned in C++ primer by lippman and lajoie.. where is the problem.. Do reply please.
5
2346
by: wesley | last post by:
Hi All. i am new to C++. I know that in order to use cout, i need to include <iostream>. I have done this, but i still get errors when i try to output to the screen. Is there a file that needs to reside in the same folder as the project? I know that in java, this is the case. Please help. Thank Wesley
1
2141
by: lars.uffmann | last post by:
Hello everyone! I just debugged a pretty huge project, eliminating basically every memory leak that would occur with the current configuration files, at least according to the mtrace() tool from the library <mcheck.h>. Now the very last bugs I seem to be incapable of eliminating are: - 0x000000000061f460 Free 387310 was never alloc'd 0x2aaaab053b53 - 0x000000000061f040 Free 387311 was never alloc'd 0x2aaaab053b53
11
41282
by: gumboots | last post by:
Hi there guys, I've recently purchased "Sam's Teach Yourself C++ Fifth Edition" (About a week before the 6th edition came out) I'm trying to work through the book, but in trying to compile Hello World, I keep getting an error instead of it making the program. I've looked around the internet for a reason, but come up stuck. My only assumption would be that the fifth edition is upgraded to suit newer compilers? (I downloaded Visual C++...
0
9621
marktang
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...
0
10264
Oralloy
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...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8937
agi2029
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...
1
7461
isladogs
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...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.