473,395 Members | 2,798 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,395 software developers and data experts.

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 1759
On Oct 5, 11:12Â*pm, "Lew...@gmail.com" <Lew...@gmail.comwrote:
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.com" <Lew...@gmail.comwrote:
>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>.

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.com" <Lew...@gmail.comwrote:
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 <ostreameverywhere else (and just <iosfwdin
your headers).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
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.com" <Lew...@gmail.comwrote:
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
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...
17
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 ...
34
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...
8
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...
21
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...
6
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...
4
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
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...
10
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.