There is high backward compatibility of C++ with C. So, you can include <stdio.h> to grant you access to the printf() function for the output. C++ provides an I/O that is more powerful and type-safe. Your application is more robust when using the type-safety features from C++, but you can still use the scanf() for your input. Iostream class gives you access to the methods and objects you will require for both input and output. You can think of the i/o in terms of bytes stream. We refer to it as an output from an application to a file, printer, or screen. On the other hand, if it is from the keyboard, we call it an input.
Output with Cout
If you are familiar with programming language C, you know that we use << to shift bits towards the left. An example is 3<<3 gives us 24. The left shift will double the value such that three left shifts get to multiply by 8.
In C++, overloads in the ostream class such that it supports strings, float, and int types. The example is how you need to do the text output by stringing together several items between the<<.
Cout<< “the texts”<< intvalue << floatdouble << endl;
Here, each of the << is a function call making the peculiar syntax possible. The end result returns a reference to the ostream object. So the example above looks like this:
Cout.<<(“the texts”) . cout .<< (intvalue ) .cout. << (floatdouble).cout.<< (endl) ;
The printf in C function can format output using the Format Specifiers like %d. As for C++, cout will format output too using a different way.
Use of Cout to Format Output
The object count belongs to the iostream library. Remember that you should include it with a
We derive the iostream library from istream, which is for input, and ostream, for output. When you want to format text output, you insert manipulators in the output stream.
Any function that alters the characteristics of the input and output stream is a manipulator. Manipulators are an overload function that returns a reference to the calling object. An example is cin for input or cout for output.
Endl is a type of manipulator that ends a line as it starts a new line. You can call the function endl (cout); but that is not the appropriate way to practice. You can use it like cout<<” the texts” <<endl<<endl; // Two blank lines.
Both parameter versions of setf use a mask. When the bit is in both the first and second parameters, it becomes set. When the bit only appears in the second parameter, it becomes clear. The values floatfield, adjustfield, and basefield below are composite flags. They can be several flags or together. A basefield with the values oxoeeoo is similar to that of dec |oct | hex.
Setf ( ios_base:: hex, ios_basefield) ;
So, it will set the hex by clearing all three flags. On the other hand, adjust field is right | left | internal as floatfield is fixed | scientific.
You can also explore other programing languages to find those that suit you.