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

C++ manipulation using iomanip library

I am new to C++ STL libraries and need help. I want to add two numbers suppose A = 4555 and B = 50, and output them as: 4555   +50 4605 Another Examples: 500000 + 12 500000       +12 500012 If i am storing both A and B in integer data type while…
0
votes
2 answers

How to manipulate general output (not numbers or variables) in C?

Ok so I am doing this assignment in C and I was wondering if C has output manipulators like setw from c++? I know how to manipulate numbers and stuff but I don't know how to manipulate general output. E.g I want to output "process" and "count" with…
0
votes
2 answers

Truncating with setw

Is there a way that I can force setw to truncate? Say that I want to get the output: blah blah blee le bu blah blah blee Is there a way to make this work: string foo{"bu blah blah blee le"}; cout << setw(foo.size() - 3) << foo.data() + 3 <<…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
1 answer

Overloading setw( )?

I would like a setw to take two parameters and return the largest. Is this possible? How do I go about doing this? Not looking for code just some direction would be fine as I couldn't find a clear answer on-the-line.
Alexander
  • 480
  • 2
  • 5
  • 21
0
votes
3 answers

Displaying text in correct column

After getting a helpful answer here, I have run into yet another problem: displaying two or more strings in the column I want it to be displayed in. For an example of the problem I have, I want this output: Come here! where? not…
wrongusername
  • 18,564
  • 40
  • 130
  • 214
0
votes
1 answer

Creating a table with cout, copied code formats differently

I've spent like 3 hours creating with the ASCII characters a table, and at the end i've correctly done one...But the problem is really weird...if i copy the table code and paste it again in the same program it formats differently! Why is it doing…
Super N
  • 15
  • 3
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
2 answers

C++ setw not aligning columns

I've got an ostream called os that I use like this: os << rec.lastname << " " << rec.firstname << setw(30) << rec.phonenum; And the output is showing up like this: WITT CANDACE 250-939-5404 PERKINS THEODORE …
mshindal
  • 578
  • 6
  • 17
0
votes
1 answer

Setw() in C++ isn't responding as I expected

So the below code works fine, with one exception: #include #include #include using namespace std; int main() { int value1, value2, value3, value4; float calcMean,calcStDev; // Input values from keyboard …
Student
  • 1,197
  • 4
  • 22
  • 39
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
1 answer

Lining columns up

Solved! This is what I wrote: cout << setw(4) << "Students"; cout << setw(20) << "Hours Worked"; cout << setw(20) << "of Total Hours"; cout << endl; for (int i = 0; i < students; i++) { cout << setw(20); cout << names[i]; cout <<…
Quaxton Hale
  • 2,460
  • 5
  • 40
  • 71
0
votes
1 answer

setw of a specific integer with set precision in C++

I'm learning the setw and setprecision functions, so here is what I've been trying so far and I have a few questions. #include #include using namespace std; int main() { float y = 1.25; cout << fixed << setw(10) <<…
user2943407
  • 409
  • 3
  • 5
  • 13
0
votes
1 answer

setw not found in MSVC 2013 or NetBeans

I'm trying to write some simple code to learn cout formatting, and both the IDEs listed in the title complain that they can't find/resolve the identifier setw(). Here is my code: #include #include #include using…
spartanhooah
  • 183
  • 4
  • 15
0
votes
2 answers

setw within a function to return an ostream

here is my function ostream margain(std::string firstWord) { ostream x; x << std::setw(20) << firstWord; return x; } in main I want to use the function as follow std::cout<< margain("start") << "````````````````````````````````````" <<…
aah134
  • 860
  • 12
  • 25
0
votes
1 answer

why is setw not working?

#include #include #include using namespace std; ifstream f("atestat.in"); ofstream g("atestat.out"); int n,i,nr=0; float v[100]; void a(int n) { for(i=1;i<=n;i++) f>>v[i]; for(i=1;i<=n;i++) …
Juggl3r
  • 3
  • 1
  • 5