iomanip Questions
10
Solved
How can I print 0x0a, instead of 0xa using cout?
#include <iostream>
using std::cout;
using std::endl;
using std::hex;
int main()
{
cout << hex << showbase << 10 <...
1
Solved
I am learning C++ and my goal is to have a table beautifully displayed in console. I tried using std::left and std::right I/O manipulators, but now that I look at my code I cannot figure out what e...
1
Solved
cppreference says:
When used in an expression out << setprecision(n) or in >> setprecision(n), sets the precision parameter of the stream out or in to exactly n.
The example on the bo...
3
I have a bunch of integers that I put into stringstreams. Now I want to change the stringstreams into strings while keeping a constant precision with the strings. How would I do that? I know I can ...
Kierkegaard asked 25/2, 2011 at 3:17
0
I'm looking at possible designs for a custom stream class. Half an hour of searching on- and off-site have not led to an answer to my queries, so I'm asking a new question instead.
Take std::endl a...
Bratton asked 31/5, 2021 at 17:44
4
Solved
I am running into a formatting issue on floating-point values, in the sense of returning to "default formatting".
Say I have 2 floats:
float f1 = 3.0f, f2 = 1.5f;
std::cout << f1 << " ...
Cupro asked 28/10, 2018 at 11:9
2
Solved
The cppreference page on std::setbase says:
Values of base other than 8, 10, or 16 reset basefield to zero, which corresponds to decimal output and prefix-dependent input.
How come?
Is there...
3
Solved
std::setprecision sets the number of significant figures. How do I use iomanip to set the precision?
I have always found iomanip confusing and counter intuitive. I need help.
A quick internet search finds (https://www.vedantu.com/maths/precision) "We thus consider precision as the maximum num...
3
Solved
If I wanted to output a fixed width hex number with 4 digits on a stream, I would need to do something like this:
cout << "0x" << hex << setw(4) << setfill('0') << 0x...
4
Solved
I created a Vector class in C++ and it works great for my problems. I am now cleaning it up, and I ran into the following piece of code:
std::ostream& operator<<(std::ostream &output...
2
Solved
Is it possible to make ostream output hexadecimal numbers with characters A-F and not a-f?
int x = 0xABC;
std::cout << std::hex << x << std::endl;
This outputs abc whereas I wo...
5
Solved
The following code reproduces my problem:
#include <iostream>
#include <iomanip>
#include <string>
void p(std::string s, int w)
{
std::cout << std::left << std::set...
Pemmican asked 21/3, 2015 at 22:47
3
Solved
I'm trying to get my output to look like this:
size time1 time2
-------------------------------
10 4 8
100 48 16
1000 2937 922
10000 123011 3902
100000 22407380 830722
And I know I need to use s...
2
Solved
I found this question already asked, but the answer everybody gives is
std::cout << std::setw(5) << std::setfill('0') << value << std::endl;
which is fine for positive nu...
3
Solved
I have read several topics about the display of floating point numbers display in C++ and I couldn't find a satisfying answer.
My question is: how to display all the significant digits of a...
Intend asked 26/10, 2013 at 18:12
3
Solved
Does the following invoke undefined behavior?
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <experimental/iterator>
int main() {
long double values...
Lupien asked 7/6, 2019 at 17:50
1
I am confused with the C++ function std::get_money defined in the <iomanip> header file. What is the use of get_money as per programming concept?
I have the following code using std::get_mon...
2
Solved
When using scanf() and its variants, the format specifier %i will accept data as hex (prefixed "0x"), octal (prefixed "0"), or decimal (no prefix), so for example the strings "0x10", "020", and "16...
4
Solved
I'd like to pass a list of manipulators to a function, something like this:
void print(const vector<std::smanip>& manips) {
// ...
for (auto m : manips)
cout << m;
// ...
}
w...
4
Solved
Take this a minimal working example
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setw(10) << "aaaaaaa"
<< setw(10) << "bb...
4
As shown in the tutorial http://www.cplusplus.com/reference/iomanip/setprecision/
// setprecision example
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setpre...
1
When the monetary value is zero, std::put_money doesn't output the '0' character as expected. I can't find anything explaining this behaviour.
example:
#include <iostream>
#include <iomani...
1
Solved
This piece of code printed 0 on my machine, but I expected 0.3. What's wrong? I'm using g++ 6.3.1 on latest Arch Linux. Compilation flags seem unrelevent.
#include <iostream>
#include <ss...
Circe asked 5/3, 2017 at 4:42
4
Solved
Most IO stream manipulators are regular functions with the following signature:
std::ios_base& func( std::ios_base& str );
However some manipulators (including the most frequently used o...
Embellishment asked 29/10, 2016 at 18:13
2
Solved
Let's say that I want to print something simple like this table:
January 1
February 2
March 3
April 4
May 5
June 6
July 7
August 8
September 9
October 10
November 11
December 12
I'd like to acco...
Aylward asked 19/10, 2016 at 13:13
1 Next >
© 2022 - 2024 — McMap. All rights reserved.