Questions tagged [setw]

`std::setw` is a `C++` function used to sets the field width to be used on output operations.

Defined in the <iomanip> include file. See C++ reference page on setw.

119 questions
3
votes
3 answers

I need something in c# which work like the setw() in c++

I am using a richTextBox in c#. I need to display strings of different length inside one richTextBox but these strings should be perfectly aligned.. this is an example.. abcd abcde abcde ab abc abcdef I know how to do this in c++ using…
Nina
  • 91
  • 4
  • 11
3
votes
1 answer

How does std::setw work with string output?

I am trying to use set width setw for string output to an output file, however, I am not able to make it work. I have with me the following example. // setw example #include #include #include int main () { …
AwaitedOne
  • 992
  • 3
  • 19
  • 42
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
2 answers

How to format text using std:out setfill std::setw std:right with one padding space

I just want to format a string and an integer value with right justify. There is no problem to do this without leading space before the integer value. bytes.....................123981 total bytes..............1030131 But it should look like…
seizu
  • 477
  • 4
  • 9
2
votes
2 answers

Printing a table C++

I am trying to print a table that looks like this: Number of Queues Oc 2 3 4 5 50,000 average-max average-max average-max average-max 100,000 average-max …
deepseapanda
  • 3,717
  • 8
  • 32
  • 39
2
votes
1 answer

C++ cout list with decimals aligned using setw(x) not put_money

C++ Code runs well, but currently outputting values to right but justified left and not lining up on the decimal. Can't use put_money, what am I missing? Attempted using fprint and put_money, confirmed with classmate we're supposed to use…
2
votes
3 answers

std::setfill and std::setw for input streams?

Consider this code: int xx; std::cin >> std::setfill('0') >> std::setw(4) >> xx; When sending 12 to the standard input I am expecting the value of xx to be 1200 and when sending 12345 I am expecting it to be 1234. However, it seems std::setfill and…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
2
votes
1 answer

prepending number with 0's

Possible Duplicate: Print leading zeros with C++ output operator (printf equivalent)? #include #include int main() { int n = 16; std::cout << ???(5) << n << std::endl; } I want the output to be 00016 setw() prepends…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
2
votes
2 answers

setw() imbues wrong output on strings containing UTF-8 multi-byte characters/code points

I need to output some data that may be UTF-8 multi-byte and I need to keep them formatted using setw(). When the characters are multi-byte sequences, aligement is lost and setw() doesn't work correctly. //#include #include…
George Kourtis
  • 2,381
  • 3
  • 18
  • 28
2
votes
2 answers

Using c++ setw to try to align second column

I'm trying to make sure that the second column in the output is aligned and it seemed like setw would be the solution but not matter what I do the second column is always off. This is the output I get from the code below... 1> 123 10> 234 but I…
cpd1
  • 777
  • 11
  • 31
2
votes
2 answers

Truncate C++ string fields generated by ostringstream, iomanip:setw

In C++ I need string representations of integers with leading zeroes, where the representation has 8 digits and no more than 8 digits, truncating digits on the right side if necessary. I thought I could do this using just ostringstream and…
Ian Durkan
  • 1,212
  • 1
  • 12
  • 26
2
votes
2 answers

How do you limit the maximum amount of characters in user input in C++?

I want it so that when the user inputs more than 5 characters, something will happen, instead of just skipping the rest. In this code, if you type in more than 5 characters, it will only show the first 5 characters. I want to put an "if" statement…
Leroterr1
  • 73
  • 2
  • 2
  • 6
2
votes
2 answers

How to use setw with objects

I'm trying to format output using the NTL library (a number theory library). One of the objects is the GF2X object, which is a polynomial represented as a string of coefficients. A quick example: GF2X a = GF2X(5,1); a++; cout<
Teofrostus
  • 1,506
  • 4
  • 18
  • 29
1
vote
2 answers

C++ setw() function does not cater for character output width on screen

IDE used Eclipse It is said to use setw() and setfill() function to format your text using cout . I tried that but if you see the text does not align on the screen because lets say in first line what compiler does is type Reg No. and fill rest with…
1
vote
1 answer

how do I get 'Additional' to line up with 'For $39.99'? I've tried \t and setw

how do I get width from the beginning of the new line so 'Additional' aligns right under 'For'? char choice; cout<<"Package A: For $39.99 per month, 4 gigabytes are provided.\n" <
mmbkp
  • 11
  • 2