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
0
votes
1 answer

Formatting using using C++ in Bloodshed

I have to rewrite fucntion p1() as p2() to mimic p1() exactly, using only and I keep getting errors that state invalid operands of types long long unsigned int and "unresolved function type" to binary operator<< The code is here: void…
user2101463
  • 343
  • 1
  • 4
  • 14
0
votes
1 answer

How to get the sum of 3 columns of existing output using

I'v wrote a program for class which uses a for loop to have the user enter a values and it gives you a table with a loop counter, show number entered, and product. I'm trying to get the sum of All 10 numbers in each column to display at the end of…
0
votes
0 answers

Linux C++ Raw Socket Sniffer - recvfrom() fails when ostringstream introduced

I am writing a packet sniffer in C++ utilizing streams instead of printf() to store and create output. The problem I've run into is that recvfrom() seems to fail and return -1 when I have two or more statements that generate output using a…
Jeremiah
  • 86
  • 4
0
votes
1 answer

std::setw() considering special characters as two characters

Why is std::setw() considering special chars as two chars ? Is there any easy and stylish way to solve this ? Eg : #include #include int main() { std::cout << std::left << std::setw(10) << "ok" << "ok" << std::endl; …
user1527491
  • 895
  • 10
  • 22
0
votes
0 answers

Using setfill for preceding zeros?

When I run the following program it displays the preceding zeros correctly: #include #include using namespace std; int main() { //Code int num1, num2, num3, num4, num5, num6; cout << "Enter ONE line…
user3281580
  • 53
  • 1
  • 2
  • 5
0
votes
2 answers

Reading integer

Here's the code I'm trying to change string binary = "000000100001000100010000000100000" bitset<32> set(binary); cout << hex << set.to_ulong() << endl; The code shows 2112010 but I want it to show 02112010.
0
votes
1 answer

Why won't this manipulator link with -O3?

I have a manipulator defined: inline std::ostream& my_manip(std::ostream& os); Which I am using like so: std::cout << my_manip << ...; All of this compiles just fine using Boost.bjam in both debug and release mode. However, when it comes time to…
fbrereto
  • 35,429
  • 19
  • 126
  • 178
0
votes
1 answer

C++ how to show exact digits of fraction part

Is there any way in C++ (or boost lib) to show a given number digits of fraction part? But I don't want to print the trailing 0 in fraction part (eg. 1.000, 1.500). See this case: cout << std::setprecision(3) << 5.0/7.0 << endl; // 0.714 cout <<…
Stan
  • 37,207
  • 50
  • 124
  • 185
0
votes
1 answer

Reset properties of std::cout for integers or doubles in C++

At various places in my code, I set certain stream properties, such as in std::cout << fixed << 4.56342;, in order to manipulate how an integer or double appears when printed to standard out. Sometimes during a particular runtime flow, std::cout is…
synaptik
  • 8,971
  • 16
  • 71
  • 98
0
votes
0 answers

C++ Word Wrap Within Column

I need to output some columns in c++ that look like this: Lower Upper Line case case Digits Spaces Other ------ ------ ------ ------ ------ ------ To print out some results from a file read, etc, etc. Is there anyway to do…
apttap
  • 468
  • 2
  • 7
  • 17
0
votes
1 answer

C++ template method to choose correct way of printing data

I have a program, written in C++, that uses matrices and I would like to print them out. In the program, matrices are either of type integer or unsigned char. This is the code I'm using right now to do the printing. template void…
martega
  • 2,103
  • 2
  • 21
  • 33
0
votes
1 answer

Iomanip errors with std::left/right

I'm trying to left justify one side of a line and right justify the other side of the line, but im having trouble getting the right side to right justify. Could anyone catch my error? //The following program will declare #include #include…
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
-1
votes
2 answers

Can't for the life of me get this to align in C++

been trying to get this to align, and every source has told me to use left and setw, but no matter how I format it I can't seem to get it to work. Anyone have any ideas? #include #include #include using namespace…
-1
votes
2 answers

c++ ostream output with setw

I have an output file name out using the below code to add a string to the text file: string foo = "Hello, foo"; out << foo; How can I customize a string to input into out file adding string and numbers with a specific width using setw(7) Your…
Adam Tr.
  • 9
  • 4
-1
votes
2 answers

set precision return statement C++

I want to return a double from a function with a set precision! It is that possible ? I want an accuracy of 10-5 ! For example : double f(double a ,double b) { //something like return.setprecision(6); return (a+b)/2; }
Vasiu Alexandru
  • 103
  • 3
  • 16
1 2 3
12
13