Hi!
I wanted to know how to have animated text, like displaying each letter at a different time.
Please can u telll me!
Hi!
I wanted to know how to have animated text, like displaying each letter at a different time.
Please can u telll me!
Last edited by stuart_cpp; 07-08-2006 at 12:17 PM.
Well, if you have the text saved in a string, you could do something like this:
It's simply a loop, displaying one character at a time.Code:string Text = "***ANIMATION***"; int Len = Text.size(); for ( int i=0; i<Len; i++ ) { cout<< Text[i]; }
Thanks so much twomers!!
I was told you should really type
instead for good measure.Dont really know why but hey.Code:for ( int i=0; i !=Len; i++ )
I don't see how that is better for good measure as if there was some fault and it jumped about the value of int Len then it would keep going.
I think the != thing is needed for vectors and whatnot, but I don't really think it makes a difference. It yeilds the same effect, and what bumfluff said holds a lot of ground!
It's not a requirement to do so. It's more an issue of good practice.
While probably open for debate, it is preferable to deal with the != operator instead of < or <= operators in for loop headers. This is so because generic algorithms for standard container types are much more picky in the choices we can make for operators. And loops are usually controlled with the != operator. As such, in an effort to maintain a single coding style across our program (and our programs), it is best one gets used to the != operator.
There is another reason... more debatable. And that is simply, it makes more sense to use != instead of < because it better captures the step nature of this type of loops.
Overall, it is a matter of preference. But do consider the shift to !=. It will pay later on.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
The same for <= or < operators. Don't you think?Originally Posted by bumfluff
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Or couldn't you just use each when they are needed? I think for a 'for' loop, the '<' / '<'defines the acceptable scope for the loop better than the '!=' does ... if you know what I mean.
As I said, it is debatable... unless, you are using generic algorithms. On that case, you don't have a choice.
The underlying principle is thus consistency in our choices. This should always be our primary motivation.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Is's much safer I woud say. With < or <= it can never be out of bounds even if there is a mistake in the increment .Originally Posted by Mario F.
Kurt
Really?Originally Posted by ZuK
Do provide an example in which the choice of those operators would break in one instance and not on another.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Code:for ( int i=0; i<10; i++ ) { i+= 12; }Code:for ( int i=0; i!=10; i++ ) { i += 12 }
this will only write to buffer[0] and buffer[2];Originally Posted by Mario F.
this will segfault for shureCode:char buffer[3]; for ( i = 0; i < sizeof(buffer); ++i ) { buffer[i]=0; ++i ; by mistake; }
KurtCode:char buffer[3]; for ( i = 0; i != sizeof(buffer); ++i ) { buffer[i]=0; ++i ; by mistake; }