Java-like functions?

I was wondering, i'm making a console game, and want to write string letter by letter. instead of copy/pasting my letter-by-letter code all the time, can i make a function similar to java? E.g i write letterByLetter();


P.S Letter-by-letter code:
1
2
3
4
5
for (int i = 0; i < str.length(); i++)
	{
		cout << str[i];
		Sleep(100);
	}
Last edited on
Sure, why not. Is there something wrong with the code you have here?
You mean this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void letterByLetter(string str)
{
  for(int i=0;i<str.lenght();i++)
  {
    cout << str[i];
    Sleep(100);
  }
}

int main()
{
  letterByLetter( "test" );
  return 0;
}
Excactly. Thanks for the help!
Topic archived. No new replies allowed.