C++ programming language part- 63 Streams
Streams
A stream is a sourse or destination for collection of
character. Streams are two types: Output
streams, allow you to write or store characters and Input streams, allow you to
read or fetch characters.
The class ios is
a virtual base class for the istream (Input stream) and ostream
(Output stream). The isstream (Input and Output stream)
is a class with multiple inheritance from both istream and ostream.
The header file contains all of the classes.
User-define streams
User-define streams are in the form of files. A file is linked
to a stream. before a file can be opened, a stream must be obtained.
ifstream-derived from istream, used
to file input(reading)
ofstream-derived
from ostream,used for file output (writing)
fstrean- derived from io stream, used for both
The following programs deal with file input and output with
respect to using fundamentals and user-define data types. Objects called ofil
and Ifil of class ofstream are created and associated
with a file named "int.txt"
Program 46-1
//steam.demo
#include
void main()
{
ofstream
ofil("int.txt"); //
object would be any name
ofil<<12 o:p="">12>
} //
open this text file and watch information from notepad
Program 46_2
//file
output
#include
void
main()
{ ifstream ifil("int.txt"); //object would be any name
int p,q,r;
ifil>>p; // like cin
ifil>>q;
ifil>>r;
cout<
//
information from text file named int.txt
File Input and
Output with String
Program
46_3
#include
void main()
{
ofstream
nova_sfil("string.txt");
nova_sfil<<"
This is Nova System";
}
// open this
text file and watch information
Program
46_4
//file output
#include
void main()
{
ifstream sfil("string.txt"); //object would be any name
char
cstr[30]; // like cin
sfil>>cstr;
cout<
}
//
information from text file named int.txt
Part- 86 assign the content of twostring
জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯