Hello,
I am beginner in C++ and I am trying to understand some features.
1 At first, I do not really understand how to use manipulators...
For example, if I have an integer (=286286), and I want to convert this value in hex or oct format, I can use the following code:
1 2 3 4 5 6 7 8
|
#include <iostream> // std::cout, std::dec, std::hex, std::oct
int main () {
int n = 286286;
std::cout << std::hex << n << '\n';
std::cout << std::oct << n << '\n';
return 0;
}
|
Great it has converted, the result is displayed in the console, but in fact it seems to be useless if only done like this...
What if I want to use the results for further treatment in the program?
How to say in C++ language "resultConversion=hex(Integer)"?
2 Why does the definition in the reference tab, it is mentioned "ios_base& hex (ios_base& str);" ? Why mention this while we type "std::cout << std::dec << n"?
Thanks for those will spend a little time to explain.