473,769 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What Can I do with "ostream"

Usually, when we program with C++, we like to include the
header"iostream ", but it's too big, so i want to use the header
"ostream" (only use it to output), as follows ,there is a
piece of code what i think can do this.. but the compiler can't give
me a good news. what can i do.

//------------------------------------------------------------------
// source code
//------------------------------------------------------------------
#include <ostream>
int main(int argc, char **argv)
{
ostream os;

int forTest1 = 1;
char forTest2 = '1';
os << forTest << " " << forTest2 << "\n";

return 0;
}

// ps: compiler : VS2003.net

Oct 5 '07 #1
4 1791
On Oct 5, 11:12Â*pm, "Lew...@gmail.c om" <Lew...@gmail.c omwrote:
Usually, when we Â* program with C++, we like to include the
header"iostream ", but it's too big, so i want to use the header
"ostream" Â* Â*(only use it to output), as follows ,there is a
piece of code what i think can do this.. but the compiler can't give
me a good news. Â*what can i do.

//------------------------------------------------------------------
// source code
//------------------------------------------------------------------
#include <ostream>

int main(int argc, char **argv)
{
ostream os;
std::ostream& os( std::cout );

Alos note that you did not specify a
namespace in your code.

--
Chris Val

Oct 5 '07 #2
On 2007-10-05 15:24, Chris ( Val ) wrote:
On Oct 5, 11:12 pm, "Lew...@gmail.c om" <Lew...@gmail.c omwrote:
>Usually, when we program with C++, we like to include the
header"iostrea m", but it's too big, so i want to use the header
"ostream" (only use it to output), as follows ,there is a
piece of code what i think can do this.. but the compiler can't give
me a good news. what can i do.

//------------------------------------------------------------------
// source code
//------------------------------------------------------------------
#include <ostream>

int main(int argc, char **argv)
{
ostream os;

std::ostream& os( std::cout );
Also not that std::cout is declared in <iostream>.

To the OP: In what way is <iostreamto large? If it is you can either
use <fstreamand write to a file, or use <cstdioand use the C
functions to write to stdout.

--
Erik Wikström
Oct 5 '07 #3
On Oct 5, 3:12 pm, "Lew...@gmail.c om" <Lew...@gmail.c omwrote:
Usually, when we program with C++, we like to include the
header"iostream ", but it's too big, so i want to use the header
"ostream" (only use it to output), as follows ,there is a
piece of code what i think can do this.. but the compiler can't give
me a good news. what can i do.
//------------------------------------------------------------------
// source code
//------------------------------------------------------------------
#include <ostream>
int main(int argc, char **argv)
{
ostream os;
int forTest1 = 1;
char forTest2 = '1';
os << forTest << " " << forTest2 << "\n";
return 0;
}
// ps: compiler : VS2003.net
With just an ostream, you can't do very much; you need an
ofstream, or something along those lines. But because ofstream
derives from ostream, most of the source code doesn't need to
know about it. So typically, you'll #include <iostreamand
<fstreamin main, or in whatever function evaluates the command
line args, and <ostreameverywh ere else (and just <iosfwdin
your headers).

--
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
Oct 5 '07 #4
On Oct 6, 12:57Â*am, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-10-05 15:24, Chris ( Val ) wrote:


On Oct 5, 11:12 pm, "Lew...@gmail.c om" <Lew...@gmail.c omwrote:
Usually, when we Â* program with C++, we like to include the
header"iostream ", but it's too big, so i want to use the header
"ostream" Â* Â*(only use it to output), as follows ,there is a
piece of code what i think can do this.. but the compiler can't give
me a good news. Â*what can i do.
//------------------------------------------------------------------
// source code
//------------------------------------------------------------------
#include <ostream>
int main(int argc, char **argv)
{
ostream os;
std::ostream& os( std::cout );

Also not that std::cout is declared in <iostream>.
[snip]

My apologies, I was completely focused on the syntax :-)

Thanks for the correction.

--
Chris Val

Oct 6 '07 #5

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

Similar topics

3
3596
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would be "public interface Value{}" in Java! class IntValue : public Value{ private: int _value; public:
17
3516
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example using std::cin; using std::cout;
34
6469
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment operator. Here's what I'm trying to do. I've defined class Complex as class Complex { friend ostream &operator<<( ostream &, Complex & ); public: Complex( float = 0.0, float = 0.0 );
8
4374
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could somebody explain it to me? I am using MSVC 6.0. Thanks a lot,
21
4117
by: Alf P. Steinbach | last post by:
Just because there seems to be a lack of post-standard _correct_ tutorials: <url: http://home.no.net/dubjai/win32cpptut/>. Disclaimer: written this evening so perhaps there are "bugs" in the presentation -- are there? Plea: if someone takes the time to convert the word document to clean xhtml perhaps with stylish clear readable layout, then it will be an incentive for me to go on to write a next part, and a next part...
6
3734
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by "typedef" to contain only either +10 or -10 and the other type named Color declared by "enum" to contain only black, blue, purple, red, white, and yellow.
4
2208
by: isanbard | last post by:
Hi all, I'd like to do something like this: #include <ostream> std::ostream cnull(0); #ifdef NDEBUG #define DOUT cnull
5
5904
by: StephQ | last post by:
At the moment I have a void member function (of a given class) that takes as input an obj of class type ofstream and write some debug information to it using the << operator. I would like to modify the code so that the function returns a "stream" that can be "sent" to cout or to a file using <<, as this would give me more flexibility. I used " " because I'm not sure I'm not using the correct terms here. :P Is there an easy way to...
10
2742
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
0
9579
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
9848
tracyyun
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...
0
8860
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
7392
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
6661
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();...
0
5293
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...
0
5432
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
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.