linuxhint.com linuxhint.com

Managing the Console with the iostream Classes in C++

In computing, the console is the computer keyboard and the computer monitor. In the past, output was sent directly to the monitor screen and not to a window displayed on the monitor. For the ordinary computer user, applications today do not use the monitor explicitly. These applications use windows displayed on the monitor. However, the computer programmer still needs to use the monitor screen. Though the programmer still needs to use...

linuxhint.com linuxhint.com

Exception Handling in C++

There are three types of software errors that exist. These are Syntax Errors, Logic Errors, and Runtime Errors. Syntax Errors A wrongly typed expression, statement, or construction is a syntax error. Consider the following two statements: int arr[] = {1, 2, 3}; //correct int arr = {1, 2, 3}; //syntax error, missing [] They are definitions of the same array. The first one is correct. The second one is missing [], and that is a syntax...

linuxhint.com linuxhint.com

C++ Access Specifiers

In C++, a class is a set of variables and functions that have been configured to work together. When the variables of the class are given values, an object is obtained. An object has the same variables and functions as a class, but this time, the variables have values. Many objects can be created from one class. One object differs from another object according to the different set of values assigned to the variables of the other...

linuxhint.com linuxhint.com

Callback Function in C++

A callback function is a function, which is an argument, not a parameter, in another function. The other function can be called the principal function. So two functions are involved: the principal function and the callback function itself. In the parameter list of the principal function, the declaration of the callback function without its definition is present, just as object declarations without assignment are present. The principal...

linuxhint.com linuxhint.com

C++ Standard Conversions

There are two entity types in C++, the fundamental types and the compound types. The fundamental types are the scalar types. The compound types are the rest of the entity types. Conversion can take place from one entity type to another appropriate type. Consider the following program: #include #include   using namespace std; int main() {     int rt1 = sqrt(5);     int rt2 = sqrt(8);     cout<<rt1<<",...

linuxhint.com linuxhint.com

C++ Types

A C++ entity is a value, object, reference, function, enumerator, type, class member, bit-field, structured binding, namespace, template, template specialization, or parameter pack. An entity can be of one or more types. There are two categories of C++ types: fundamental and compound types. A scalar is arithmetic or a pointer object type. Fundamental types are scalars, while the rest of the entity types are compound types. The memory...

linuxhint.com linuxhint.com

C++ Namespace

A namespace in C++ is a generalized scope. Its declaration begins with the reserved word, namespace, followed by a name of the programmer’s choice, and then the block in braces. The block contains basic declarations and/or definitions of C++ objects, functions, and other entities. Consider the following two scalar statements in a global scope, in the following program: #include using namespace std; int varId = 5; float varId =...

linuxhint.com linuxhint.com

How to use C++ String Class

A string literal is a sequence of characters in a constant array pointer terminated by the nul character, \0. When identified, by a variable, the string literal cannot really reduce or increase in length. Many operations cannot be done on the string literal. So, there is a need for a string class. The C++ string class is for a data structure, a collection of characters in sequence, which allows member functions and operators to act on...

linuxhint.com linuxhint.com

How to Use C++ Vector

Introduction An array is a series of same object types in consecutive memory locations. An array cannot increase ore reduce in length. A vector is like an array, but its length can be increased or reduced. A vector, therefore, has many more operations than an array. C++ has many libraries, all of which form the C++ Standard Library. One of these libraries is the container library. A container is a collection of objects, and certain...

linuxhint.com linuxhint.com

How to use C++ Pointers

The memory of a computer is actually a long series of cells. The size of each cell is called a byte. A byte is a space occupied by an English character of the alphabet. An object in the ordinary sense is a consecutive set of bytes in memory. Each cell has an address, which is an integer, usually written in hexadecimal form. There are three ways of accessing an object in memory. An object can be accessed using what is known as a...