Need an English speaker
-
I need help. Does anybody here speak English?
-
How can I help you?
-
I'm sorry but I need to sleep now. Maybe someone else can help you in the meanwhile.
-
I need to make a program that says a message on the screen, but there needs to be a delay in between each letter, so it looks as though it is being typed. That's the best way I can describe it. I hope you understand.
Thank you.
-
You could realise it with a simple loop like:
char* text = "just some letters"; for(int i; i ; i++){ cout<<text[i]; for(int j; j<1000000; j++) {} }
There might be a system function like sleep, but that depends on your system.
Maybe you find a system independent solution there:boost::timer
-
Although my Solutions depend on your operating System, it should fit your needs:
#include <iostream> // #include <unistd.h> // For Linux :) using namespace std; int main() { char* text="Hello, my name is Sarah! :)"; while(*text) { cout << *text << flush; Sleep(50); // usleep(50000); // For Linux :) text++; } cout << endl; } I would prefer this, because the for loop depends on your machine speed.
-
CarstenJ schrieb:
Although my Solutions depend on your operating System, it should fit your needs:
#include <iostream> // #include <unistd.h> // For Linux :) using namespace std; int main() { char* text="Hello, my name is Sarah! :)"; while(*text) { cout << *text << flush; Sleep(50); // usleep(50000); // For Linux :) text++; } cout << endl; } I would prefer this, because the for loop depends on your machine speed.
When i tried to compile that, it highlighted the line that says, "Sleep(50);", and it said this:
"implicit declaration of function `int Sleep(...)'"
what does that mean???
-
if ( i remember corectly ) { Sleep() is in "windows.h" } ;)
-
THE_FreaK schrieb:
if ( i remember corectly ) { Sleep() is in "windows.h" } ;)
thanks. i added #include <windows.h> and it worked.
-
CarstenJ schrieb:
Although my Solutions depend on your operating System, it should fit your needs:
#include <iostream> // #include <unistd.h> // For Linux :) using namespace std; int main() { char* text="Hello, my name is Sarah! :)"; while(*text) { cout << *text << flush; Sleep(50); // usleep(50000); // For Linux :) text++; } cout << endl; } I would prefer this, because the for loop depends on your machine speed.
Wer ist Sarah?
-
interpreter
Wer ist Sarah?
i'm guessing that carstenJ is sarah since she wrote it
-
CarstenJ schrieb:
Although my Solutions depend on your operating System, it should fit your needs:
#include <iostream> // #include <unistd.h> // For Linux :) using namespace std; int main() { char* text="Hello, my name is Sarah! :)"; while(*text) { cout << *text << flush; Sleep(50); // usleep(50000); // For Linux :) text++; } cout << endl; } I would prefer this, because the for loop depends on your machine speed.
What does the * after char and before text do?
And what does flush mean?
-
hi,
the * after char means a pointer on char elements.
flush gives the content of the buffer of the outputstream, whether it is full or not. The most other operations wait until the buffer of the outputstream is full.
Hope you understand my bad English.Bye Gartenzwerg
-
Hello mfo6463
mfo6463 schrieb:
What does the * after char and before text do?
And what does flush mean?The while loop simply loops until the char pointer "text" points to the terminating NULL character (a char string in C/C++ is terminated by a NULL-character, it has the binary value '0000 0000'). The * -operator dereferences a pointer; it just gives the content of the address, which the pointer is pointing to.
So, inside the loop we are outputting one character of the string at a time, flushing the buffer of the output-stream (so the character is immediately visible on the console screen), sleeping for 50 milliseconds (you may change it to your desired delay-time) and incrementing the text pointer. We're incrementing it, because we want to traverse through the string. At the beginning the text pointer is pointing to the character 'H'. If we increment the pointer, it jumps to the next character which is 'e'. If we increment it again, it points to 'l', and so on and so forth...If the text-pointer points to the NULL character, we know that we've reached the end of the string. If we incremented the pointer one more time, and tried to access the content of this address, we'd get a memory access error-message from the OS.
I hope it's clear now.
-
Thanks. I understand it now.
-
Dieser Beitrag wurde gelöscht!
-
Dieser Beitrag wurde gelöscht!