•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,053 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,438 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 398 | Replies: 13 | Solved
![]() |
•
•
Join Date: May 2008
Posts: 96
Reputation:
Rep Power: 1
Solved Threads: 0
Hello,
The following code works but I am having trouble formatting it with setw() and I am not sure if it possible to format it with a space so that the entire seat header fits on one line and for the rows to also fit on one line with spaces.
My code is the following:
The following code works but I am having trouble formatting it with setw() and I am not sure if it possible to format it with a space so that the entire seat header fits on one line and for the rows to also fit on one line with spaces.
My code is the following:
void Tickets::displaySeats()
{
cout << "Seats: ";
int counter = 1;
do
{
cout << counter << " ";
}while(++counter <= 30);
for(int row_i = 1; row_i < row; row_i++)
{
cout << "\nrow " << row_i << ": ";
for (int seat_j = 1; seat_j < seat; seat_j++)
cout << seating[row_i][seat_j] << " ";
}
} >I just can't get them all in one line using setw()
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: May 2008
Posts: 96
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
>I just can't get them all in one line using setw()
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.
Well I changed it and now I am getting everything to work except for 10-30 on the header. I need a space, but when I try to say the following in the "do loop", it does not work and it makes the header go down to a second line:
if(counter <= 9)
cout << counter << setw(2);
else
cout << " " << counter;
}while(++counter <= 30);Is there a way to expand the actual command prompt?
My updated code is the following:
void Tickets::displaySeats()
{
// creater the header
cout << "Seats: " << setw(2);
int counter = 1;
do
{
if(counter <= 9)
cout << counter << setw(2);
else
cout << counter << setw(1);
}while(++counter <= 30);
// show the seat availability
for(int row_i = 1; row_i < row; row_i++)
{
if(row_i <= 9)
{
cout << "\nrow 0" << row_i << ": ";
}
else
{
cout << "\nrow " << row_i << ": ";
}
for (int seat_j = 1; seat_j < seat; seat_j++)
cout << seating[row_i][seat_j] << " ";
}
}
>it does not work and it makes the header go down to a second line
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.
>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.
>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: May 2008
Posts: 96
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
>it does not work and it makes the header go down to a second line
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.
>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.
so i can't fix this?
>so i can't fix this?
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: May 2008
Posts: 96
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
>so i can't fix this?
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.
I see. I was wondering, do you know if the prompt command box will delete initial output if the information being printed is too long or will it keep the entire history? It keeps chopping off and I am not sure if it’s something that I am doing wrong or if this is common?
•
•
Join Date: Jan 2008
Posts: 1,490
Reputation:
Rep Power: 6
Solved Threads: 187
•
•
•
•
I see. I was wondering, do you know if the prompt command box will delete initial output if the information being printed is too long or will it keep the entire history? It keeps chopping off and I am not sure if it’s something that I am doing wrong or if this is common?
In Windows XP, it'll chop off the output in the command window, and I imagine in other operating systems, the same is true. I just wrote a program to count from 0 to 100,000 and it only kept about the last 300 or so lines. The numbers before 99,700 were no longer visible in the console window after the program was done, even when I scrolled up to the top.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- formatting problems (Windows NT / 2000 / XP / 2003)
- Formatting & Loading Win98 (Windows 9x / Me)
- formatting help (C++)
- Formatting in Currency (Visual Basic 4 / 5 / 6)
- Mail Formatting lost when sending from Panther "mail" app. (Mac Software)
- Problems formatting HD (Windows 9x / Me)
- formatting (Windows 9x / Me)
Other Threads in the C++ Forum
- Previous Thread: C++ Graphs
- Next Thread: Compile time error "undeclared identifier"for functions strcpy_s,strcat_s,_itoa_s



Linear Mode