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 &lt...
Moyra asked 22/4, 2011 at 21:29

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...
Exurb asked 15/8, 2023 at 14:4

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...
Icosahedron asked 16/3, 2023 at 17:42

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...
Enrobe asked 18/4, 2016 at 19:38

3

Solved

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...
Elfish asked 18/3, 2021 at 12:10

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...
Parasiticide asked 1/7, 2010 at 15:45

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...
Molybdenite asked 16/3, 2011 at 16:28

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...
Detrusion asked 7/11, 2010 at 9:23

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...
Sirrah asked 26/3, 2014 at 3:41

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...
Ontine asked 9/7, 2013 at 8:51

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...

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...
Cowley asked 21/4, 2019 at 4:55

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...
Nadaba asked 18/12, 2010 at 5:27

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...
Bouffe asked 5/2, 2013 at 7:58

4

Solved

Take this a minimal working example #include <iostream> #include <iomanip> using namespace std; int main() { cout << setw(10) << "aaaaaaa" << setw(10) << "bb...
Zymolysis asked 18/9, 2017 at 6:39

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...
Kidron asked 13/7, 2017 at 14:56

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...
Bicker asked 15/6, 2017 at 14:13

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

© 2022 - 2024 — McMap. All rights reserved.