CPP File & Stream

CPP standard library fstream is used to create a file, to read the data from a file and to write the data into a file in CPP programming. There are three data types defined in fstream library. These are: fstream: Used to create a file, to read the data from a file and to write … Read more

Categories CPP

CPP User-Defined Exceptions

CPP facilitates the feature of defining any new error by a user in a CPP program, by overriding and inheriting exception class functionality. Example: #include <iostream> #include <exception> using namespace std; class newException : public exception { public: const char * what() const throw() { return "Divide by zero error!"; } };   int main … Read more

Categories CPP

CPP Try Catch

Exception handling is necessary in an efficient code, as if it is not handled properly, further execution of code stops as soon as any exception occurs. Try, Catch and Throw are the keywords used for exception handling in CPP. Steps for Exception Handling in CPP: The suspicious code which can raise an exception is enclosed … Read more

Categories CPP

CPP Exception Handling

Exception handling is necessary in an efficient code, as if it is not handled properly, further execution of code stops as soon as any exception occurs. CPP provides numerous ways and features to handle these exceptions in CPP codes, which makes the code more vulnerable to exceptional situations. Exception can refer to any situation and … Read more

Categories CPP

CPP String Functions

String Functions are the built-in functions provided by CPP to operate and manipulate a string. CPP provides a number of string functions. Some of the MOST USED string functions are listed below:   FUNCTION SYNTAX USES strcpy() strcpy(destination, source) Copies a string from source to destination. strcat() strcat(string1, string2) Concatenates two strings. strcmp() strcmp(string1, string2) … Read more

Categories CPP

CPP Strings

A sequence of characters, internally stored in the form of an array of characters is called as string. Declaration of String: In CPP, a string can be specified in two ways: Character Array: A string declared as an array, where each character represents an element of that array, is called as Character Array. Syntax: char … Read more

Categories CPP

CPP Iterators

CPP facilitates another unique feature same as that of pointers, known as iterators. Iterators in CPP are used to access the container elements by traversing through one element to another element. Syntax 1: <Container_Type> :: iterator; Syntax 2: <Container_Type> :: const_iterator;   Iterator Functions: There are mainly two functions that are used for an iterator … Read more

Categories CPP

CPP Templates

CPP templates acts as a support for generic programming technique, where parameters in algorithms are of generic types and thus can work for a variety of data types. This feature in CPP is used to define the generic classes and generic functions.   Types of CPP Templates: Function Templates: In function templates, templates for a … Read more

Categories CPP

CPP Namespaces

A namespace in CPP is used to define a scope in order to differentiate similar functions, classes, variables etc. to define the context in which names are defined for the same name available in different libraries. Syntax: Defining Namespace namespace namespace_name { // code declarations }   Syntax: Calling the defined name namespace_name  :: code;  … Read more

Categories CPP

CPP Data Abstraction

CPP introduced the features of OOPs Concept, i.e, CPP is an object-oriented programming language which uses classes and objects for computations. However, it is not considered to be truly object-oriented programming language. An object oriented programming is based on seven fundamental principles, including data abstraction. OOPS Data Abstraction feature is used for hiding internal details … Read more

Categories CPP