Questions tagged [iomanip]

Anything related to C++ I/O manipulators, i.e. special kinds of objects that alter the behavior of streams. Inserting a manipulator into an output stream or extracting one from an input stream provides an easy alternative for configuring specific aspects of the stream operations.

Anything related to C++ I/O manipulators, i.e. special kinds of objects that alter the behavior of streams. Inserting a manipulator into an output stream or extracting one from an input stream provides an easy alternative for configuring specific aspects of the stream operations.

Simple manipulators are defined directly in the C++ standard header <iostream>. Manipulators taking arguments (i.e. functions that return actual manipulator objects) are defined in the <iomanip> standard header.

See CPPreference.com documentation for I/O manipulators.

164 questions
4
votes
3 answers

Really, what's the opposite of "fixed" I/O manipulator?

This may be a duplicate of this question, but I don't feel it was actually answered correctly. Observe: #include #include using namespace std; int main () { float p = 1.00; cout << showpoint << setprecision(3) << p <<…
rmp251
  • 4,262
  • 3
  • 27
  • 37
4
votes
3 answers

Set the number of digits for an Integer

Is there a way in C++ to make the compiler take a certain number of digits even if they first digits are 0's. For example: I have an item number that is 00001 and when I import the number from the file it displays a 1. I want it to import all five…
Alex McCoy
  • 91
  • 1
  • 2
  • 4
3
votes
1 answer

Using iomanip to format data output to a text file with Qt

I am a student programmer using QT to develop and application for work. Currently I am developing the save functions in which data is taken from a table and saved to a file. Im running into some trouble when I try to write the data into columns. Not…
Wylie Coyote SG.
  • 919
  • 5
  • 19
  • 37
3
votes
1 answer

How to align user input in C++ (not using iomanip)

My program is supposed to align inputted text based on what the user specifies, so far I've gotten it to change the width but not align the text (Left, Right, Center). I've seen but it doesn't help in my case. The code I've gotten so far…
Roy Pugh
  • 31
  • 2
3
votes
0 answers

using stream operator<< with std::endl in c++

I am trying out the following C++ class for using the stream operator << to log contents from this answer: class Log { public: Log() : m_filename( "dafault.log" ) {} // if you wanna give other names eventually... Log( const…
tinlyx
  • 18,900
  • 26
  • 81
  • 148
3
votes
1 answer

Objectives: using the iomanip library to format screen output

Hello everyone this is my code and I just help I managed to correct the first 3 questions but the rest I am still getting errors. Below is the all question : Complete the provided main() program with statements to accomplish each of the following.…
3
votes
3 answers

printf formatting equivalent in cpp's cout

I am currently a student of Computer Science, and today I received an extra-ordinary assignment, which should be written under C++. I was learning full C until today. This is more like a blind assignment. In C, I usually use…
3
votes
1 answer

Do input operands return booleans in c++?

Reading through accelerated c++, they give an example I don't understand. It's a while loop with condition (cin>>x). At this point in the script, x has been declared as a double. I understand that the loop executes as long as x successfully receives…
hedgehogrider
  • 917
  • 2
  • 11
  • 19
3
votes
2 answers

How to cut off leading digits? C++

How can I cut off the leading digits of a number in order to only display the last two digits, without using the library. For example: 1923 to 23 2001 to 01 1234 to 34 123 to 23 with only #include #include Thanks!
dubyaa
  • 199
  • 7
  • 17
3
votes
2 answers

Define an ostream modifier c++

I am generating assembly and I want to have all the generated code aligned. This includes having sth like cout<<"\t"<
niko
  • 1,048
  • 1
  • 11
  • 24
3
votes
2 answers

C++ Custom I/O manipulator for hexadecimal integers

I'm trying to write a custom I/O manipulator in C++ which can write nicely formatted hexadecimals in the form 0xFFFF according to the size of the provided integer. For example: char c = 1 becomes 0x01 short s = 1 becomes 0x0001 And so on. Can't…
nyarlathotep108
  • 4,663
  • 1
  • 16
  • 46
3
votes
2 answers

Send formatted char array to ostream without extra memory copying

I need to send a char array to ostream. Say I have the following print function: Version 1: void print(ostream &out, const char *str, unsigned len) { out << string(str,len); } Version 2: void print(ostream &out, const char *str, unsigned…
3
votes
2 answers

Why use showpoint when you can use setprecision fixed?

I don't quite understand the purpose of showpoint, i know it forces to show a decimal point, but having "cout << setprecision << fixed" is enough without the use of showpoint. Can you show me an example where showpoint is a must have?
user97662
  • 703
  • 1
  • 8
  • 21
3
votes
0 answers

Ready to use C++ iomanip wrappers?

Since raw use of the iomanip stream modifiers is a) verbose and b) error prone (sticky vs. non-sticky, etc.), for user defined types, all that stuff can be hidden in the default operator<< ... as shown here, for example. However, when formatting…
Martin Ba
  • 33,741
  • 27
  • 150
  • 304
3
votes
1 answer

Resetting output flags in C++

I'm intending to reset all output flags to default on the lines where I end using the resetiosflags function. It provides erroneous output when I attempt to do it in this manner, contrary to my expectations. #include #include…
alxmke
  • 288
  • 1
  • 17
1 2
3
10 11