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
0 answers

Inputing accentuated characters form wcin

I need to write a C++ that reads country names in Portuguese (Latin language with special characters like é and á) This is the code I am using: int main(int, const char *[]) { setlocale(LC_ALL, "en_US.UTF-8"); locale accents("en_US.UTF-8"); …
Nuno
  • 117
  • 4
1
vote
1 answer

Aligning text in the form of vertical list/or a text in C++

I want the following output to get aligned properly in the form of a table: My attempt: I created a class with member function(a function to display the products available in a store) and member variables. Then in the main function I initialized…
SIDDHARTH SINGH
  • 138
  • 3
  • 8
1
vote
1 answer

C++ output alignment

#include #include using namespace std; int main() { double start_temp, end_temp, incr, fahrenheit, celsius, kelvin; do { cin >> start_temp >> end_temp >> incr; if (start_temp > end_temp || incr <=…
Linux27
  • 15
  • 4
1
vote
0 answers

Spacing in C++ using setw()

Here's the part of my code that I can't seem to fix the spacing for. for (int i = 0; i <= 3; i++) { cout << "Name: " << accounts[i].getName() << setw(10) << "Type: " << accounts[i].getType() << setw(10) << "Number: " <<…
Phoenix
  • 33
  • 3
1
vote
2 answers

Is it possible to read files generated with C++ std::setw using Python csv reader?

I have a data file generated using C++ std::setw e.g. file << std::scientific << std::setprecision(data_precision); for (double data : a_data) { …
A. Drew
  • 37
  • 7
1
vote
1 answer

Battle Naval Assignment, can't allign an array with setw(), could you help me?

I've got an assignment, shortly described, i've got to make an simple battle naval game. I thought it would be easy but i'm stuck. But right now i'm stuck. I've got one problem, i can't properly show my array, it does't align well. It would be…
1
vote
2 answers

How to format right and left justification on the same line?

If I am making a data table to show the results of several functions, how can I use the setw(), left, and right keywords to create a table which is formatted like this: Height 8 Width 2 Total Area …
1
vote
1 answer

C++: setw() only working on first row, in loop

I am trying to parse through a text file and have it output the contents onto the console with formatting by using setw(). My problem is that only the first row is formatted correctly, with the rest defaulting back to the left. while (test) { …
Jaws88
  • 21
  • 1
  • 8
1
vote
1 answer

How do I move a decimal point left while maintaining number of digits displayed?

I currently have a function that takes in a vector of structs, including all floats, and should return some values after a simple calculation. My cout function is simply void taxPrint(std::vector &citizen) { int loops = 0; …
Cartino
  • 41
  • 1
  • 7
1
vote
1 answer

How to use setfill and setw to stock an hex value in a string variable

I read a file and transform it to hex notation like this {0x4D,x0FF,0x01} I stock it in an unsigned char array. I can print what I would like to stock but I don't achieve to stock datas in my array. I read the bitset class documentation but I am not…
1
vote
1 answer

C++ ostream fill adding a trailing 0

Hello I am having an issue formatting my output using the ostream object in C++. ostream& write(ostream& os) { os << os.fill('*') << os.width(10); return os; } This is what the output looks like: ********* 0 I'm trying to achieve 10 *s…
Devin
  • 58
  • 8
1
vote
1 answer

How to understand C++ std::setw 's inconsistent behaviour?

Given the following code: /*Formatting Output **Goal: practice using cout to format output to console **Print the variables in three columns: **Ints, Floats, Doubles */ #include #include using namespace std; int main() { …
George 2.0 Hope
  • 583
  • 1
  • 6
  • 21
1
vote
1 answer

Automatic spacing with iomanip

For the following code: cout << left << setw(20) << "Example Header\n"; cout << setw(60) << setfill('-') << "-" << endl; The second line (with the dashes) is indented by 5 spaces for some reason. I initially thought that something was automatically…
Aaron Thomsen
  • 45
  • 1
  • 5
1
vote
1 answer

C++ setw() not working as expected

I need to print some data on in the console. My code is: cout << setw(5) << left << "id" << " | " << setw(10) << left << "computer" << " | " << setw(11) << left << "subsystem" << " | " << setw(8) << left << "number" << " | " << setw(80) <<…
Egor Chubarov
  • 208
  • 1
  • 13
1
vote
3 answers

Another C++ output alignment issue

I've been trying to align the following code for the last 3 hours with zero success. Could anybody fill me in about what I'm doing wrong? My aim is to have the string literal left aligned and the variable right aligned like this: Loan amount: …
Greg. O Hajdu
  • 126
  • 2
  • 14