Hey, how can i have text that appears from cout appear as though it is being typed, i know its possible and im just wondering if anyone has any ideas as to how, or if i should use a differnt input of text other than cout to make it work, thanx
Hey, how can i have text that appears from cout appear as though it is being typed, i know its possible and im just wondering if anyone has any ideas as to how, or if i should use a differnt input of text other than cout to make it work, thanx
like this?
Code:for(int i = 0; ch[i]; i ++) { cout << ch[i]; Sleep(50); // from windows.h }
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
that should do the trick, thanx
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
ok, im not to use to using the for loop, so could you perhaps explain just a bit more as to how i should set it up..
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
Hope that helps!Code:char ch[6] = "HELLO"; for( int i = 0; // the loop's declaration ch[i]; // this checks for if the char still has content i ++ // increment the placeholder ) { cout << ch[i]; // output the current character Sleep(50); // wait 50 milisecs }
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
it does, and i get what how to use the for now but im wondring, how can i use it to do it to a string of text, (with whitespace - e.g. "Welcome to earth") lol, thanx again
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
Code:string str = "Welcome to Earth!"; for(int i = 0; str[i] != '\0'; i ++) { cout << str[i]; Sleep(50); }
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
Great, it works perfect, thanx a bunch!!!
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
np
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
what if i have two strings? how will it jump to the second string?
>> for(int i = 0; str[i] != '\0'; i ++)
alternatively -
Do you want them to both type at the same time, or one after another? If you want them to display one afte another, I'd recommend making a function -Code:string stringinstance = "This is a string"; for ( int i=0; i<stringinstance.size(); i++ ) cout<< stringinstance[i];
then just call that in mainCode:void TypeText ( stiring text ) { for ( int i=0; i<(int)text.size(); i++ ) { cout<< text[i]; Sleep( 50 ); } }
Code:int main( void ) { TypeText( "Number one" ); TypeText( "Numbertwo" ); return 0; }
Last edited by twomers; 09-02-2006 at 08:09 AM.
one after another.
here is my code. it only display the first string
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
void main() {
clrscr();
char msg[] = "This is only a test.";
char msg1[] = "I hope that this will work.";
for (int i = 0; msg[i] != '\0'; i++) {
cout << msg[i]; delay(100);
}
getch();
}
I've changed things you should change to 'Sienna' for some reason. I'd recommend my function. void main = bad. getch() to stop the program = not the best method, check out the FAQ, use std::strings instead of char[]'sCode:#include<iostream> // #include<conio.h> not standard #include<string> #include<windows.h> // for Sleep using std::string; using std::cout; // or using namespace std; for both of those void TypeText ( stiring text ) { for ( int i=0; i<(int)text.size(); i++ ) { cout<< text[i]; Sleep( 50 ); } } int main() { string msg = "This is only a test."; string msg1 = "I hope that this will work."; TypeText ( msg ); TypeText ( msg1 ); return 0; }
Oh dear
Oh, and USE CODE TAGS!!
Last edited by twomers; 09-02-2006 at 08:20 AM.
ok. thank you for your help.
Ok, you might want to cout<< "\n"; or something between the function calls to make them go on different lines.