The string class has been briefly introduced in an earlier chapter. It is a very powerful class to handle and manipulate strings of characters. However, because strings are, in fact, sequences of characters, we can represent them also as plain arrays of elements of a character type. For example, the following array: char foo … Continue reading Character sequences
Name visibility
Scopes Named entities, such as variables, functions, and compound types need to be declared before being used in C++. The point in the program where this declaration happens influences its visibility: An entity declared outside any block has global scope, meaning that its name is valid anywhere in the code. While an entity declared within … Continue reading Name visibility
Numerical Bases
Since we were kids, we have all used decimals to express quantities. This nomenclature that seems so logical to us may not seem so to an inhabitant of Classical Rome. For them, each symbol that they wrote to express a number always represented the same value: I 1 II 2 III 3 IV 4 V … Continue reading Numerical Bases
Boolean Operations
A bit is the minimum amount of information that we can imagine, since it only stores either value 1 or 0, which represents either YES or NO, activated or deactivated, true or false, etc... that is: two possible states each one opposite to the other, without possibility of any shades. We are going to consider … Continue reading Boolean Operations
Ascii Codes
It is a very well-known fact that computers can manage internally only 0s (zeros) and 1s (ones). This is true, and by means of sequences of 0s and 1s the computer can express any numerical value as its binary translation, which is a very simple mathematical operation (as explained in the paper numerical bases). Nevertheless, … Continue reading Ascii Codes
Input/output with files
C++ provides the following classes to perform output and input of characters to/from files: ofstream: Stream class to write on files ifstream: Stream class to read from files fstream: Stream class to both read and write from/to files. These classes are derived directly or indirectly from the classes istream and ostream. We have already used … Continue reading Input/output with files
Preprocessor directives
Preprocessor directives are lines included in the code of programs preceded by a hash sign (#). These lines are not program statements but directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements. These preprocessor directives … Continue reading Preprocessor directives
Exceptions
Exceptions provide a way to react to exceptional circumstances (like runtime errors) in programs by transferring control to special functions called handlers. To catch exceptions, a portion of code is placed under exception inspection. This is done by enclosing that portion of code in a try-block. When an exceptional circumstance arises within that block, an … Continue reading Exceptions
Type conversions
Implicit conversion Implicit conversions are automatically performed when a value is copied to a compatible type. For example: 1 2 3 short a=2000; int b; b=a; Here, the value of a is promoted from short to int without the need of any explicit operator. This is known as a standard conversion. Standard conversions affect fundamental … Continue reading Type conversions
Polymorphism
Before getting any deeper into this chapter, you should have a proper understanding of pointers and class inheritance. If you are not really sure of the meaning of any of the following expressions, you should review the indicated sections: Statement: Explained in: int A::b(int c) { } Classes a->b Data structures class A: public B … Continue reading Polymorphism