Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Typewriter function for windows

Display your little helpful snippets of code that may help us all get something done

Typewriter function for windows

Postby pipey85 on Sun Sep 13, 2009 5:43 pm

Code: Select all
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

//standard function
void printTyper(string toPrint)
{
   for (unsigned int a = 0; a<toPrint.length(); a++)
   {
      cout << toPrint[a];
      Sleep(500);
   }
}


//overloaded custom time version
void printTyper(int time, string toPrint)
{
   for (unsigned int a = 0; a<toPrint.length(); a++)
   {
      cout << toPrint[a];
      Sleep(time);
   }
}

//main program call
int main()
{
   string str1 = "my typewriter function"; // create a string called str1
   printTyper(str1); // send str1 to the printTyper function and watch!!
   cout << "\n\n";
   printTyper(200, str1);// overloaded version where you can set the time delay


   return 0;
}


its a pretty cool lil pair of functions :) any questions?
Pardon my n00bness, what I lack in C++ I make up for in time spent reading about C++ :P
pipey85
 
Posts: 40
Joined: Mon Jun 22, 2009 6:11 pm

Return to Snippets

Who is online

Users browsing this forum: No registered users and 0 guests