"\t" not working properly

Sometimes when I use "\t" to space things, it will skip certain elements, i.e. the tab character won't appear for some cout.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void print()

	{ 

		cout << '(' << x << ',' << y << ')' << "\t";

	}

for(int i=0; i<50; i++)

	{

		a[i].print();


		if(i==37)

			cout << "\t";


		if(((i+1)%5)==0)

			cout << "\n";



	}


If I didn't include this statement:

1
2
3
if(i==37)

	cout << "\t";


There won't be a "\t" character after I print the 37th element, even though the void print function says to tab after every coordinate (x,y). Anyone know what's going on?
Last edited on
It would help to know what a is, and what its print() method is.
Last edited on
If you are using a[i] to call the print function you probably aren't calling
1
2
3
4
5
6
7
void print()

	{ 

		cout << '(' << x << ',' << y << ')' << "\t";

	}

void print function

It is just a normal function with a return type of void and a function name of print. There is no such thing as a void function. It is a function which happens to return nothing(void).

Also '\t' is a single character. Though I would suggest cout << '(' << x << ',' << y << ")\t" The error you probably get is it goes out of bounds and goes to next line from overflow. I would just output a new line after each one instead of a tab. Or maybe more often than every 5th.
Topic archived. No new replies allowed.