Hỏi về vòng lặp for cuối, chạy chương trình dấu "-" không nằm sát lề

int main()
{
	int table[10][8] = {
		{0,0,2,0,5,6,3,0},
		{5,1,9,0,0,2,3,2},
		{0,0,0,1,0,0,0,0},
		{1,1,1,0,2,2,2,1},
		{5,3,2,0,0,2,5,5},
		{2,2,1,0,1,1,0,0},
		{3,2,5,0,1,2,0,4},
		{3,0,7,1,3,5,2,4},
		{0,2,6,1,0,5,2,1},
		{4,0,2,0,3,2,1,0}};

	cout << setw(54/2+6) << "Selesperson" << setw(54/2) << endl;
	cout << setw(7) << "Model" << setw(2) << ":" << setw(4);
	for (int i = 1; i <= 8; i++)
		cout << i << setw(4);
	cout << ":" << setw(7) << "Totals" << endl;

	for (int i = 1; i <= 54; i++)
		cout << "-";
	cout << endl;
	cout << setw(4);
	for (int i = 0; i < 10; i++)
	{
		cout << i + 1 << setw(5) << ":" << setw(4);
		for (int j = 0; j < 8; j++)
			cout << table[i][j] << setw(4);
		cout << ":" << setw(4) << endl;
		
		
	}
	
	for (int i = 0; i < 54; i++)
		cout << "-";
	cout << endl;
}

This post was flagged by the community and is temporarily hidden.

endl rồi mà vẫn còn setw hả b?

bạn đưa hết đoạn code lên đây đi, để mọi người debug

This post was flagged by the community and is temporarily hidden.

mình đưa code rồi bạn

This post was flagged by the community and is temporarily hidden.

Bạn giải thích mình với.endl rồi, bắt đầu vòng lặp mới mà vẫn con setw(4)

Chắc là cái setw nó được đưa vào bộ điệm rồi, và endl không lấy nó ra. Nếu bạn để ý thì dòng cout << i + 1 << setw(5) << ":" << setw(4); khi nó thực hiện lần thứ 2 trở đi thì nó không có cái setw nào, nhưng nó vẫn thụt vào.

This post was flagged by the community and is temporarily hidden.

Wow, cuối cùng mình cũng phát hiện ra sự khác biệt giữa std::endl\n. Cảm ơn bạn nhiều :smiley:

This post was flagged by the community and is temporarily hidden.

Vì thế dùng std::endl tốt hơn phải không bạn ?

This post was flagged by the community and is temporarily hidden.

thì tất nhiên endl tốt hơn rồi

This post was flagged by the community and is temporarily hidden.

test kiểu gì bây giờ, kiểm tra thời gian chạy à?

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?