User Tools

Site Tools


computer_science:programming:cpp

C++

C++ is a programming language.

Information about it will be added to this page.

There will also be links to bits of codes for easy access:

Formatting cout

It is possible to format cout's output by including #include <iomanip> Then get access to these:

cout << fixed << result << endl; // This will set the display to use fixed representation (default of 6 digits?)
cout << fixed << setprecision(2) << result; // This will force cout to isplay only 2 decimals and will round to reach this result
cout << result << endl; // this would still show with the previous setprecision setting.
 
cout << setprecision(3) << result2; // the variable is not affect by set precision, so it would now show 3 decimals
 
cout << fixed << setprecision(2) << setw(15) << left << result << "End of line" <<endl;

Using setw we can force the display of a certain number of characters. In this case, if the variable is more than 15 characters, it will be truncated, if not then white spaces will be added. The next (optional) setting (in this case “left” determines the orientation of the text.

computer_science/programming/cpp.txt · Last modified: 2021/10/02 04:59 by mana