I am trying to get my program to write text a letter at a time instead of a entire line at a time how is it that I go about doing that?
I know this is prolly really obvious but I cant find it in the furoms so I figured I would ask.
I am trying to get my program to write text a letter at a time instead of a entire line at a time how is it that I go about doing that?
I know this is prolly really obvious but I cant find it in the furoms so I figured I would ask.
A for loop to print each character - say cout << string[i];
A delay to wait a while between printing characters - say Sleep(1000);
Flush output to make sure you see something - say cout.flush();
here, i copied the "void sleep" method from some site, and i wrote the code
Code:#include <iostream> #include <time.h> using namespace std; void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); } int main(){ char word[] = "Supercalifragilistoiusomg"; cout << word << endl; cout << "now letter byletter people \n" ; int x; for (x=0;x<26;x++){ cout << word[x] << " "; sleep(100); } cout << endl; cin.get(); }
Last edited by rodrigorules; 11-26-2005 at 02:17 PM.
is there any way to gt a string length to get it to automaticlly know how many characters are in the string. Because if you make x larger than the string then alot of random characters pop up. So i was wondering if you could make something like
I know that isnt the actually syntax but that is like what I want.Code:x =strl word[];
And thank you very much for helping me with the text display thing.
Code:#include<iostream> #include<fstream> using namespace std; int main() { string example = "alksdfhlksdhflkhsflkhsdlfkhsaelkhflksahef"; int length = example.length(); cout << length; cout << "Or end a for-loop" << endl; for( int i = 1; i <= example.length(); i++) cout << i << " " ; return 0; }
Thanks so much Enahs that helps A WHOLE LOT. As far as I knwo this is going to be my last question it have nothing to do with this but better than making a new thread for something this dumb. What is the difference betweenandCode:#include "program.h"
Because I am making my own headers for my program and I keep having to add them to the include file of my dev-cpp directory before it will let me use them. I need to be able to use them from the program directory not dev-cpp. (Mainly because I want to be able to share my code with other windows users). so they can learn from it.Code:#include <program.h>
If you wanna use your own headear file use " " - it should be in your directory
otherwise use <> - this means the header is either in system32 or in compiler directory
And also when you are determinating the length of a string, that is char[xxx] do it like this:
Code:char string[]; int length = strlen(string);
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
what do those mean? I made my header files and now my program wont run.Code:1 C:\Dev-Cpp\Game\Game.cpp In file included from Game.cpp 5 C:\Dev-Cpp\Game\game.h colors: No such file or directory. C:\Dev-Cpp\Game\G__~1.EXE Game.o: No such file or directory. C:\Dev-Cpp\Game\G__~1.EXE no input files
i think that you have included "game.h"
but haven't created such file, or maybe you did but haven't placed it in right directory.
Give us the source!!!
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
well I cant send you my source. my comp is really really messed up and is barely lettng me get on the net. but anyways I have a FOLDER named game, then I have all my files in it including the source, headers, and whatever else I may need, but it keeps telling me the files dont exist? it is wierd I know they are there but the program says they dont exist. I even tried adding the directory to my include files under project properties and it didnt work.
If you have those header files in a separate folder, are you remembering to include that part of the path in your includes?
Code:#incude "game\game.h"
Yep that was the problem thanks sean