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:

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] << " ";
	}
}

Recommended Answers

All 13 Replies

What kind of problem are u experiencing with setw()? Did you add the header file "iomanip"?

What kind of problem are u experiencing with setw()? Did you add the header file "iomanip"?

yep - I just can't get them all in one line using setw()

>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.

>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.

>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.

>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?

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.

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.

Good idea. Thanks. I decided to leave it formatted the way it is and basically it’s all nice and aligned except the header from 10-30 does not have any spaces as the window is not wide enough.

Thanks :)

> 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?
Choose properties of your console window, then set the buffer size to what you want.
The max is 9999 lines.

Or you could always do myprog > results.txt and get all the output, no matter how long it is (well up to your file size / disk limits).

> 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?
Choose properties of your console window, then set the buffer size to what you want.
The max is 9999 lines.

Or you could always do myprog > results.txt and get all the output, no matter how long it is (well up to your file size / disk limits).

I was wondering how to actually implement this. For instance where would I incorporate it and are there any standard library templates that I need to refer to?

No. Salem's example was an example of a console-command.
Here's another example

dir > myfiles.txt

This will put the output from "dir" (old dos command for finding files) in the (newly created) file 'myfiles.txt'.

The ' > ' operator just redirects the output that normally would be on your screen, you a file. It has nothing to do with c++, it's just a console (or even DOS?) function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.