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
1
vote
1 answer

Setfill and setw not working

Basically I am trying to setfill and setw to create a fixed table to display information stored in an array however it doesn't appear that set width is working and I'm not sure why. Here is the code I am using: const int MAXWIDTH = 10; cout << left…
broliverparker
  • 217
  • 2
  • 15
1
vote
3 answers

Setw and setfill equivalent in BASH

Could you please tell me what the equivalent BASH code for the following C++ snippet would be: std::cout << std::setfill('x') << std::setw(7) << 250; The output is: xxxx250 Thanks for the help!
raytracer
  • 13
  • 3
1
vote
1 answer

C++ Text Formatting using setw doesnot work with QT's QTextEdit

I want to write a data to a file. I am formatting that Data using C++'s iomanip function, setw to set width of Text Field. Source code is as below: std::ofstream…
Coder
  • 845
  • 1
  • 10
  • 20
1
vote
1 answer

Making a 6x6 grid with a 2d array

this is what I have so far and I get an error: setw was not declared in this scope void grid (void) { for (int r = 0; r < 6; r++) { for (int c = 0; c < 6; c++) { cout << "-------------" << endl; cout…
Shay
  • 19
  • 6
1
vote
1 answer

fstream and setw not aligning output properly

setw does not seem to be aligning things here for me, and I can't figure out why that is. Inserting \t does push things to the right, but I'd like to have tighter control over the formatting of the output. Any ideas? #include #include…
Blueshift
  • 160
  • 1
  • 6
  • 19
1
vote
1 answer

align right and left without knowing the string width

Ok, so I have to make a program with an output that looks like this: Gross Amount: ............... $3575.00 Federal Tax: ................ $ 536.25 State Tax: .................. $ 125.13 Social Security Tax: ........ $ 205.56 Medicare/Medicaid Tax:…
Jesse
  • 25
  • 1
  • 7
1
vote
3 answers

Having trouble with iomanip, columns not lining up the way I expect

finishing up a long project and the final step is to make sure my data lines up in the proper column. easy. Only I am having trouble with this and have been at it for longer than i wish to admit watching many videos and can't really grasp what the…
Tyler Kelly
  • 564
  • 5
  • 23
1
vote
1 answer

Why doesn't setw(n) work here?

Here is my problem: Given three variables, a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in a 15 position field on the same line, in such away that scientific (or e-notation or…
nullByteMe
  • 6,141
  • 13
  • 62
  • 99
1
vote
0 answers

setw() length of string is larger than configured limit

I am planning to organize output strings in double column in terminal console, where setw() is applied to configure the widths of each columns. I nonetheless find if length of the string, which is to be displayed in the right column, exceeds the…
Jake0x32
  • 1,402
  • 2
  • 11
  • 18
1
vote
2 answers

Beginner C++ - Simple random walk program with a strange setw bug

I've been tasked with creating a very simple random walk program for a C++ class. I wrote it and was fairly sure everything was correct but I am getting this strange bug. From 0 to 10 the steps line up even though the coordinates show that its…
TimmyG
  • 13
  • 1
  • 4
1
vote
1 answer

Distributing spaces between words equally C++

Basically what I'm trying to do is to distribute spaces equally between words of a given string. This is what I did: istringstream s("En el infinito y mas alla"); string token; while( s >> token ) { cout << token << setw(10); } However, this…
1
vote
3 answers

justify text with setw

I want to justify the output text like this 0x29823d80 0x10019b8 / 0 00000000000000000000000000000001 0x37449e60 0x10dfc / 12 00000000000000000001000000000000 However with this statement fout << std::setw(5) <<…
mahmood
  • 23,197
  • 49
  • 147
  • 242
1
vote
1 answer

How to format the output

I would like to have a clean formatted output, but the result is not exactly as clean as I want. Below is my function which shows the output, followed by the output. I am using Dev-C++. Thank you for your help. void student::show(string name, int…
T4000
  • 231
  • 1
  • 7
  • 24
0
votes
0 answers

Why does setw misbehave when displaying the second variable (you.date)?

Im using setw to display my content, but one value has too much spaces which decreases the spaces from others this is my code: #include #include #include #include using namespace std; int main() { struct…
0
votes
0 answers

output formatting error getting extra dots

my output formatting is wrong, here is display function below: std::ostream &Seat::display(std::ostream &coutRef) const { if(isEmpty()){ coutRef<<"Invalid Seat!"; } //check if seat no is valid or not else…
Jimmy S
  • 19
  • 2