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.

186 questions
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
  • 1,168
  • 2
  • 14
  • 22
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
  • 1
  • 7
  • 17
3
votes
2 answers

Reading a double from an istream in Hex

Given double foo I can assign it from a hex format string using sscanf like this: sscanf("0XD", "%lg", &foo) But I cannot seem to get an istringstream to behave the same way. All of these just write 0 to foo: istringstream("0XD") >>…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
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,128
  • 1
  • 11
  • 25
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
  • 5,275
  • 2
  • 26
  • 64
3
votes
2 answers

C++ iomanip Alignment

I'm trying to align my output but for some reason I can't get it to how I want it, and it's really frustrating. The title won't align right. I don't know if I'm using setw() properly. #include using std::cout; using std::endl; #include…
4tehlolxz
  • 117
  • 1
  • 1
  • 6
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
  • 37,187
  • 33
  • 183
  • 337
3
votes
2 answers

Setting precision on std::cout in entire file scope - C++ iomanip

I'm doing some calculations, and the results are being save in a file. I have to output very precise results, near the precision of the double variable, and I'm using the iomanip setprecision(int) for that. The problem is that I have to put the…
Ivan
  • 19,560
  • 31
  • 97
  • 141
3
votes
1 answer

set precision of digits before the decimal point?

I have already viewed this thread but it does not account for using negative numbers if i use setfill( '0' ). #include #include using namespace std; int main() { //Code int num1; cin >> num1; cout << setw(5) <<…
user3281580
  • 53
  • 1
  • 2
  • 5
3
votes
1 answer

Splitting strings by newline character in C++

If I have two tables stored in std::string variables, how could I display them side-by-side? In particular... I have std::string table1 which contains the following: X | Y ------- 2 | 3 1 | 3 5 | 2 I have std::string table2 which contains the…
synaptik
  • 8,971
  • 16
  • 71
  • 98
3
votes
6 answers

C++ - How do you loop back after user input?

In my previous question, I got this answer to work so that if the user inputs more than 5 characters in the nation name, it will output an error. #include #include int main() { using namespace std; const int maxchar =…
Leroterr1
  • 73
  • 2
  • 2
  • 6
3
votes
3 answers

1 byte integer doesn't convert i/o formats

I wrote the code below which inputs a number in hex format and outputs it in decimal form:- #include #include #include using namespace std; int main() { uint8_t c; cin>>hex>>c; cout<
AvinashK
  • 3,309
  • 8
  • 43
  • 94
2
votes
2 answers

Can't understand how to make istream manipulator

I want to make an int32_le_read(x) manipulator that reads binary from a file and writes to x. I implemented the int32_bin_manip class class bin_manip { public: bin_manip(); ~bin_manip(); friend std::istream&…
Max Nov
  • 23
  • 2