Deleting the last one

Hey, I would like to is there any way for deleting last item in output?
For example;
for(i=0;i<10;i++)
{
cout<<i<<" ";
}
I want delete last whitespace in output. How I can do that?
Why dont you just delete that one from the code?

Otherwise, you can use \b //backspace character// on the next line when you wanna delete that white space
But \b doesn't work..
when i wrote
cout<<"d";
cout<<"\b";
It doesn't delete the 'D' character in output.
????
Can you explain why you would wanna do that in the first place?
1
2
3
4
for(i=0;i<10;i++)
{
cout<<i<< (i==9 ? "" : " ");
}
The part of code which is problem for me
for(j=0;j<10;j++)
{
if(b[j]==1)
{
cout<<j<<" ";
}
}
Array 'b' has ten element each controlling one statement to be true (if the 1st statement is true b[0]=1)
the values of 'j' is the numbers I need, but there must not be a whitespace after last one.
@Leon
Try this..
1
2
3
4
5
6
7
for(j=0;j<10;j++)
{
   if(b[j]==1)
      { cout<<j;
        if(j<8)
           cout << " "; }
 }
@whitenite1
This won't work, because depending on statements the last printed value of 'j' can be ,for example '6', it means again whitespace will be printed.((((
@Leon..
Sorry, I made a small error in the example. Here it is corrected !

1
2
3
4
5
6
for(j=0;j<10;j++)
{
    cout << b[j];
        if (j < 9) // Have j to equal 1 less than maximum value of j in for loop
           cout << " "; // whitespace ONLY printed upto, but not including, last j in for loop
 }

Hope this is better...
closed account (zb0S216C)
Moschops's code works, you know. It's got my vote. +1 to Moschops.

Wazzak
Topic archived. No new replies allowed.