Easy question. involving text only

Hello, everyone.

I was wanting to write a program to write a note like I would be typing it normally instead of just all popping up at once. I was wondering how I would go about making it type it out and not a pop up?

Eg:

1
2
3
4
5
6
7
8
9
//note

#include <iostream>

usingnamespace std;

int main();{
cout << "Hello, /n how was your day today? Mine was ok enough to call a great day. /n  ... etc
} 



excuse my syntax I have not checked it for errors ... I am just asking how to make it type instead of print the cout part..?
Last edited on
The hint I could give without sitting down and coding it right now is that you could us a do while loop to output one letter at a time with a timers in the while to pause for a certain period of time between each char. You could store your message in a std::string.
Last edited on
I am a self taught learning C++ machine ... but needless to say I do remember using loops in python but have not learned yet in C++.

Therefore your advice does not even yield a thought as to how to start this. This is not a project for grade, just a simple question that needs some examples in code please... I am not in a rush as I am not timed/graded so I will wait with excitement over this small amount of knowledge haha

EDIT: sry I mean to compile that paragraph before posting here is the result:

I != Smart
Last edited on
@Yoda

Here's a program I found on this site, and it does what you need. Look it over, and adapt it to your needs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RPG Typewriter.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

/********************************************
 *               Introduction               *
 * Hello there, and welcome to my           *
 * type writer class for c++. I made this   *
 * to provide the user a simple solution    *
 * for creating messages that are displayed *
 * like ones in an RPG. You can use this in *
 * ANY of your projects royalty free! And,  *
 * you don't need to credit me... but it    *
 * would be nice of course. At least tell   *
 * me if you decide to use it so that I see *
 * it at work in your game/project =D       *
 *                                          *
 *               How to use                 *
 * You can create a message in three simple *
 * steps. First, you must declare a type    *
 * writer object. Next, use                 *
 * setmessage(), to initiate your type      *
 * writer's message. Once that's done, use  *
 * write() to display your message. Note:   *
 * in the write() function, there is a      *
 * parameter called speed which stands for  *
 * the number of characters displayed per   *
 * second. Well, that's it. I hope you      *
 * enjoy! ;)                                *
 *                                          *
 * SuperSonic                               *
 ********************************************/

struct typewriter
{
    public:
        char message[256];

        void setmessage(char input[256])
        {
            counter = 0;
            messagedone = false;
            for(int i = 0; i < 256; i++)
            {
                message[i] = input[i];
            }
        }

        void write(int speed)
        {
            while(!messagedone)
            {
                if(message[counter])
                {
                    if (message[counter] != ' ')
						Beep(800,100);

					cout << message[counter];
					counter++;
					
                }
                else
                {
                    messagedone = true;
                }
                Sleep(1000/speed);
            }
        }
    private:
        int counter;
        bool messagedone;
} Write;

int main()
{
    Write.setmessage("Hello world.\nDo you like the type-writer effect?\nThis can be used in any program.");
    Write.write(10);
	Sleep(2000);
	Write.setmessage("\n\nThank you for viewing, and trying out, my program!!");
	Write.write(30);
    Sleep(2000);
	Write.setmessage("\n\nGood-bye\n\n\t");
	Write.write(30);
    return 0;
}
Topic archived. No new replies allowed.