What Can I do with "ostream"

L

LewGun

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
 
C

Chris ( Val )

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::eek:stream& os( std::cout );

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

Guest

std::eek:stream& os( std::cout );

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

To the OP: In what way is <iostream> to large? If it is you can either
use <fstream> and write to a file, or use <cstdio> and use the C
functions to write to stdout.
 
J

James Kanze

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 <iostream> and
<fstream> in main, or in whatever function evaluates the command
line args, and <ostream> everywhere else (and just <iosfwd> in
your headers).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
BettinaPol

Latest Threads

Top