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

How to use setw(x) in a toString method in c++ and put it in a variable or suggestions?

I have a Book class, and I want to implement a toString method in c++, using setw(x), to format in a properly mode. I want to print something like that: > cout<
beni
  • 9
  • 1
0
votes
1 answer

How to properly use setw() to format output?

I am trying to format my output as: 1 [tab] First Name: John [tab] Last Name: Smith [tab] Age: 20 [tab]daysInCourse: {35, 40, 55} Degree Program: Security My current code is: { cout << left << setw(15) << studentID; cout << left << setw(15)…
0
votes
0 answers

Aligning output column using setw in C++

I have been reading about setw for column widths, however setting a width for each colum does not seem to be aligning the last two columns. I have tried using the right align, however it also changes alignment for the left two columns as well, which…
Nicholas Chiu
  • 67
  • 1
  • 7
0
votes
0 answers

Setw not seeming to work consistently in output file

The program I'm building is meant to output students names, their 5 scores, and their grade from a input file named "students.txt" into an output file named "output.txt". All of the calculation required is correct, but the formatting of the output…
0
votes
1 answer

How can I display a $ sign with a value while using setw and setprecision in c++

I want to display the dollar sign next to its value in the second column, but if I convert the value into a string, the setprecision doesn't work and it displayed more decimals than I would like. Currently the formatting doesn't look good. My…
Saim Beg
  • 3
  • 1
0
votes
1 answer

Interaction between setw and double quoted string character

I'm trying to make a receipt, andbalways want the " kg" to be ONE SPACE after the weight, and also "$" just before both 'costperkg' and 'totacost' Initially using setw to format the output, could not get it to work, got it done with ostringstream.…
0
votes
2 answers

Using setw when output istringstream to a string, why the length is not right?

I view an example of setw on cppreference. It use setw to set the width. In this example it suppose to extract a string to 'arr', and it set width 6. But why 'arr' only have 5 characters, why the result is "hello" not "hello,"? Thank you for your…
0
votes
1 answer

setw(n) and alignment not working the way I need it to - C++

Here is my code for context. This is my second homework assignment intro to programming course and I have used everything we've learned in this assignment. I am not allowed to use anything I have not learned. The part I am concerned with is the…
Taelle Echon
  • 31
  • 1
  • 6
0
votes
1 answer

C++ aligning characters to display neatly with any input implemented

I am having trouble keeping the ":" and the "$" aligned with whichever input the user implements through the cin command which is "numTShirts". It stays aligned if implemented 10 and under but discount goes out of place with any other…
0
votes
1 answer

std::setw for the whole operator<< of user-defined type

We know, that the std::setw() influence only on the next output. So, what standard practice to align the whole operator<< of user-defined type in table output: class A { int i, j; public: friend ostream& opeartor<<(ostream& out, const A& a)…
Kirill Golikov
  • 1,354
  • 1
  • 13
  • 27
0
votes
2 answers

Aligning the left most character of each value in a column

For a lab of mine we need to display the output values in a column following a statement of what the value is for. Example of what I need. Amount of adult tickets: 16 Amount of children tickets: 12 Revenue from…
Derek M
  • 29
  • 1
  • 4
0
votes
2 answers

C++ Beginner: How do I prevent the text in my table from pushing any text to the right of it?

I am working on a very basic program for my Fundamentals I class and I have everything 98% working as intended. This program takes the names of three grades, averages them, and outputs them into a table, but since assignmentName[] is on the same…
user8645395
0
votes
0 answers

Using setw() properly

I'm still a beginner at coding but I am really confused about how setw() works. I am trying to align my outputs but I am unable to do so. I've looked at cplusplus website but obviously I still cant figure it out. Maybe someone can provide an example…
Panthy
  • 1,605
  • 4
  • 19
  • 27
0
votes
2 answers

c++ setw not working the way I need it to

The idea is to print 4 shapes, the first two shapes print fine, and the next two shapes using setw are meant to be the mirrors but still printed bellow as they are. My understanding was that setw made a kind of text box that started outputting from…
Max Mcgregor
  • 101
  • 9