Presented By:
Mayank Seth
Arun Brijwasi
File streams in C++.
Fstream library
Assert library
Math library
Ctype library
CONTENTS
C++ uses the file stream as an interface
between the programs and the data files.
FILE STREAMS IN C++
In C++ we use IOSTREAM library which
provides cin and cout object for taking input
and output from console.
To read and write from a file we use the
standard C++ library called FSTREAM.
It defines three more data types :
Ofstream
Ifstream
fstream
FSTREAM LIBRARY
This data type represents the output file
stream and is used to create files and to write
information to files.
Either ofstream or fstream object may be
used to open a file for writing.
Example: For opening a file for writing data
into it we use the object of ofstream class:
ofstream outfile;
outfile.open(“myfile.txt");
OFSTREAM
This data type represents the input file stream
and is used to read information from files.
And ifstream object is used to open a file for
reading purpose only along with the open
function.
Example: For opening a file for writing data
into it we use the object of ifstream class:
ifstream infile;
infile.open(“myfile.txt");
IFSTREAM
This data type represents the file stream
generally, and has the capabilities of both
ofstream and ifstream which means it can
create files, write information to files, and
read information from files.
The fstream object can be used for with the
open function for both reading from and
writing to file.
FSTREAM
Assertions are statements used to test
assumptions made by programmer.
The assert library provides a
preprocessor macro assert that is useful
during program development.
ASSERT LIBRARY
When an assert macro is invoked its
parameter expression is checked to see
whether its value is zero or not
If value is non-zero program continues
normally.
If value is zero the program produces an error
message .
Following is the syntax for assertion:
assert(expression);
The assert library is a c based library thus
when including this library we use cassert.
ASSERT LIBRARY
C++ being superset of C, supports large
number of useful mathematical functions.
In order to use these functions you need to
include header file- <math.h> or <cmath>.
MATH LIBRARY
VARIOUS FUNCTIONS OF MATH LIBRARY
Function name Meaning
double sin(double) : This function takes angle (in degree) as an
argument and return its sine value
double cos(double) : This function takes angle (in degree) as an
argument and return its cosine value
double tan(double) This function takes angle (in degree) as an
argument and return its tangent value.
double sqrt(double) : This function takes number as an
argument and return its square root value.
int abs(int) This function takes integer number as an
argument and return its absolute value.
Function name meaning
double pow(double, double) : This function takes one argument as base
and other as exponent.
double hypot(double, double) : This function requires two sides of the
right angled triangle to give output as its
hypotenuse
double floor(double) : This functions returns the integer value
lesser or equal to argument passed in the
function.
double fabs(double) : This function returns the absolute value of
any number.
double acos(double) : This function returns the arc cosine of
argument.
double asin(double) : This function returns the arc sine of
argument.
double atan(double) : This function returns the arc tangent of
argument.
double ceil(double) : This function returns the smallest integer
as double not less than the argument
provided.
Function name Meaning
double cosh(double) : This function returns the hyperbolic
cosine of argument provided.
double tanh(double) : This function returns the hyperbolic
tangent of argument provided.
double log(double) : This function takes a number and returns
the natural log of that number.
Contains function prototypes for functions that
test characters for certain properties.
Since it is a C based library we write
<cctype.h> to include it in our c++ progam.
CTYPE LIBRARY
Function Name Meaning
int isalnum(int c) Checks whether the passed character is
alphanumeric.
int isalpha(int c) Checks whether the passed character is
alphabetic.
int iscntrl(int c) Checks whether the passed character is
control character.
int isdigit(int c) Checks whether the passed character is
decimal digit.
int isgraph(int c) Checks whether the passed character
has graphical representation using
locale.
int islower(int c) Checks whether the passed character is
lowercase letter.
int isprint(int c) Checks whether the passed character is
printable
VARIOUS FUNCTIONS OF <CTYPE>
HEADER FILE
Function Name Meaning
int ispunct(int c) Checks whether the passed character is a
punctuation character.
int isspace(int c) Checks whether the passed character is
white-space.
int isupper(int c) Checks whether the passed character is
an uppercase letter.
int isxdigit(int c) Checks whether the passed character is a
hexadecimal digit.
int tolower(int c) Converts uppercase letters to lowercase.
int toupper(int c) Converts lowercase letters to uppercase.
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.

FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.

  • 1.
  • 2.
    File streams inC++. Fstream library Assert library Math library Ctype library CONTENTS
  • 3.
    C++ uses thefile stream as an interface between the programs and the data files. FILE STREAMS IN C++
  • 5.
    In C++ weuse IOSTREAM library which provides cin and cout object for taking input and output from console. To read and write from a file we use the standard C++ library called FSTREAM. It defines three more data types : Ofstream Ifstream fstream FSTREAM LIBRARY
  • 6.
    This data typerepresents the output file stream and is used to create files and to write information to files. Either ofstream or fstream object may be used to open a file for writing. Example: For opening a file for writing data into it we use the object of ofstream class: ofstream outfile; outfile.open(“myfile.txt"); OFSTREAM
  • 7.
    This data typerepresents the input file stream and is used to read information from files. And ifstream object is used to open a file for reading purpose only along with the open function. Example: For opening a file for writing data into it we use the object of ifstream class: ifstream infile; infile.open(“myfile.txt"); IFSTREAM
  • 8.
    This data typerepresents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files. The fstream object can be used for with the open function for both reading from and writing to file. FSTREAM
  • 9.
    Assertions are statementsused to test assumptions made by programmer. The assert library provides a preprocessor macro assert that is useful during program development. ASSERT LIBRARY
  • 10.
    When an assertmacro is invoked its parameter expression is checked to see whether its value is zero or not If value is non-zero program continues normally. If value is zero the program produces an error message . Following is the syntax for assertion: assert(expression); The assert library is a c based library thus when including this library we use cassert. ASSERT LIBRARY
  • 11.
    C++ being supersetof C, supports large number of useful mathematical functions. In order to use these functions you need to include header file- <math.h> or <cmath>. MATH LIBRARY
  • 12.
    VARIOUS FUNCTIONS OFMATH LIBRARY Function name Meaning double sin(double) : This function takes angle (in degree) as an argument and return its sine value double cos(double) : This function takes angle (in degree) as an argument and return its cosine value double tan(double) This function takes angle (in degree) as an argument and return its tangent value. double sqrt(double) : This function takes number as an argument and return its square root value. int abs(int) This function takes integer number as an argument and return its absolute value.
  • 13.
    Function name meaning doublepow(double, double) : This function takes one argument as base and other as exponent. double hypot(double, double) : This function requires two sides of the right angled triangle to give output as its hypotenuse double floor(double) : This functions returns the integer value lesser or equal to argument passed in the function. double fabs(double) : This function returns the absolute value of any number. double acos(double) : This function returns the arc cosine of argument. double asin(double) : This function returns the arc sine of argument. double atan(double) : This function returns the arc tangent of argument. double ceil(double) : This function returns the smallest integer as double not less than the argument provided.
  • 14.
    Function name Meaning doublecosh(double) : This function returns the hyperbolic cosine of argument provided. double tanh(double) : This function returns the hyperbolic tangent of argument provided. double log(double) : This function takes a number and returns the natural log of that number.
  • 15.
    Contains function prototypesfor functions that test characters for certain properties. Since it is a C based library we write <cctype.h> to include it in our c++ progam. CTYPE LIBRARY
  • 16.
    Function Name Meaning intisalnum(int c) Checks whether the passed character is alphanumeric. int isalpha(int c) Checks whether the passed character is alphabetic. int iscntrl(int c) Checks whether the passed character is control character. int isdigit(int c) Checks whether the passed character is decimal digit. int isgraph(int c) Checks whether the passed character has graphical representation using locale. int islower(int c) Checks whether the passed character is lowercase letter. int isprint(int c) Checks whether the passed character is printable VARIOUS FUNCTIONS OF <CTYPE> HEADER FILE
  • 17.
    Function Name Meaning intispunct(int c) Checks whether the passed character is a punctuation character. int isspace(int c) Checks whether the passed character is white-space. int isupper(int c) Checks whether the passed character is an uppercase letter. int isxdigit(int c) Checks whether the passed character is a hexadecimal digit. int tolower(int c) Converts uppercase letters to lowercase. int toupper(int c) Converts lowercase letters to uppercase.