This method is a small part of a game I worked on. The purpose of the method is to create a life-like output of words, to mimic dialogue and feel more realistic when characters are communicating.
The method takes a string which is the words to be output, an int which represents, in milliseconds, the pause between each word, and another string, speaker, which is the name of the person speaking.
This method works in a fascinating way and really is able to break down a barrier which is often present in text based games, the lack of realistic interaction.
I am not sure if I will post the entirety of this adventure on my site, but I will continue to update on methods which go into the game.
<pre> /* Method which creates life like speech by dividing up and outputting single words seperated by intervals */ void speak(string statement, int pause, string speaker){ cout << endl; //temp string and stringstream are created string temp; stringstream ss(statement); cout << speaker << ": "; //Creates pauses between the output of words while(ss >> temp){ std::this_thread::sleep_for(std::chrono::milliseconds(pause)); cout << temp << " " << flush; } } </pre>