1 letter At A Time

Started by
4 comments, last by SSJGaz 20 years, 8 months ago
Can some one please tell me how i can make my text show up a letter at a time, instead of the whole text showing up at once? (Console)
[SSJGaz][Newbie C++ Programmer]
Advertisement
Yeah, im a noobie myself but here's the info...

char NameHere = "WhatEver";

cout << NameHere[0];
its not wanting to show for some odd reason.

cout<
Another Example:

for(int i = 0; i <= 8; i++)
{
cout<<}

Output:

W
h
a
t
E
v
e
r



that would do this...
--After Building and runing the program--


W


edit: Bah forgot to tell you this... the numbers start at zero on the left...and count up. 01234...etc... Of how ever big the string is...

[edited by - DarkWhoppy on July 26, 2003 9:22:34 PM]

[edited by - DarkWhoppy on July 26, 2003 9:26:53 PM]
Visit the 3DHangout
Are you referring how to do this to strings or what?
Do you mean something like this?

string foo="meet foo";const int t=1000;//set whatever delay you wantfor(int i=0;i<foo.length();i++){    cout<<foo[i];    Sleep(t);//one second intervals}//for





--{You fight like a dairy farmer!}

--{You fight like a dairy farmer!}

quote:Original post by DarkWhoppy
Yeah, im a noobie myself but here''s the info...

char NameHere = "WhatEver";

cout << NameHere[0];
its not wanting to show for some odd reason.

cout<
Another Example:

for(int i = 0; i <= 8; i++)
{
cout<<}

Output:

W
h
a
t
E
v
e
r



that would do this...
--After Building and runing the program--


W


edit: Bah forgot to tell you this... the numbers start at zero on the left...and count up. 01234...etc... Of how ever big the string is...

[edited by - DarkWhoppy on July 26, 2003 9:22:34 PM]


[edited by - DarkWhoppy on July 26, 2003 9:26:53 PM]


i want it to go sideways not downwards. sorry i''v been awake 40hrs working on my project so my posts are sucking
[SSJGaz][Newbie C++ Programmer]
quote:Original post by DarkWhoppy
Yeah, im a noobie myself but here's the info...

char NameHere = "WhatEver";

cout << NameHere[0];
its not wanting to show for some odd reason.

cout<
Another Example:

for(int i = 0; i <= 8; i++)
{
cout<<}

Output:

W
h
a
t
E
v
e
r


few mistakes if you haven't caught them already. First, you have to use char *NameHere otherwise you're only allocating space for a single char. You'll probably end up getting an error too trying to assign stuff the way you're doing now.

Second mistake is you should be going from i=0 to i<8; not <=. Also it's probably a better idea to use strlen(NameHere) to get it's length instead of putting an actual number there. You won't always know what the length of the string is.

And lastly, you can enclose your code using [source] tags so the formating doesn't show up all messed up in your post.




--{You fight like a dairy farmer!}

[edited by - Greatwolf on July 26, 2003 9:49:57 PM]

--{You fight like a dairy farmer!}

You could use some time function and always output only one char at a time, so you would have something like this:

#pragma comment(lib,"winmm.lib")#include <windows.h>#include <iostream>int main(){    int curChar = 0;    int curTime, startTime;    char lpstrText[] = "Your Text\n";    startTime = timeGetTime(); // get current (=start) time    do    {        curTime = timeGetTime(); // get current time        if (startTime+500 <= curTime) // if half a second has passed        {            std::cout << lpstrText[curChar++];            startTime = curTime;        }        if (HIWORD(GetKeyState(VK_RETURN))) // if the user presses return the whole text will be there at once        {            std::cout << &lpstrText[curChar];            curChar = strlen(lpstrText);        }    } while (curChar < strlen(lpstrText));    system("PAUSE"); // wait so one can still watch the output ;)    return 0;}
[My Lousy Page | Kings Of Chaos | Vampires | [email=lordlethis@hotmail.com]email.me[/email]]

This topic is closed to new replies.

Advertisement