473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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<must have been
declared, and typedef'd to ostream as well) ?

Mar 5 '07 #1
1 2026
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 <iosfwdcontains 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
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...
1
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...
9
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...
4
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
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...
9
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...
5
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...
1
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.