Was this really necessary?
And why don't you use a string like this.
And why didn't you useCode:char str[PF] = "Hello World";
instead of:Code:const int PF = 12;
Code:#define PF 12
Alright, i know this is partial "Noobish" but, bare with me. I for one think it's a great wonder, for making cool effects
Yes i made it ;P
What it does, is use a for() loop with the end set to the total elements of the Array. It then couts the first element, which is a (A=0) A then gets incremented within the loop(by 1), until it reaches the end, which is the last string in the Array:
Leave the stupid remarks out, please.Code:#include <cstdlib> #include <iostream> #include <string> #include <windows.h> using namespace std; #define PF 12 // Definites a constant int slow_print(); int main() { slow_print(); cin.get(); cin.ignore(); return EXIT_SUCCESS; } //FUNCTION::::::::::::::::::::::::::::::::::: int slow_print(){ int speed; // Pause speed between the couts string words[PF] = { //Out array which holds our message "H", "E", "L", "L", "O", " ", "W", "O", "R", "L", "D"}; int a = 0; //Will start from element 0 and increment until 0 > PF which is 12 cout << "How fast do you want the printing effect to appear?(Milliseconds): "; cin >> speed; //OMG U NOT KJNOW THIS?? for (int l = 0; l < PF; l++){ //..Seriously Sleep(speed); cout << words[a]; // Couts the first element of the Array, which then increments to next element. a++; } };
Was this really necessary?
And why don't you use a string like this.
And why didn't you useCode:char str[PF] = "Hello World";
instead of:Code:const int PF = 12;
Code:#define PF 12
Auto Writer??
Nice one.
Much better than a series of string objects. This solution is elegant, concise, and uses modern C++.Code:char my_string[] = "Hello World!"; std::vector<char> my_string_container(my_string, my_string + strlen(my_string)); std::for_each(my_string_container.begin(), my_string_container.end(), [](char ch) { Sleep(speed); std::cout << ch; });
Last edited by Fovea; 05-17-2011 at 04:47 PM.
Hell_Demon (05-18-2011),Melodia (05-17-2011),PunkS7yle (05-18-2011)
really now?Code:#define PF 12 // Definites a constant
Comments are for explaining WHY something happens, not just explaining the line in english
^ Never would have guessed what these do, thanksCode:int speed; // Pause speed between the couts string words[PF] = { //Out array which holds our message cout << words[a]; // Couts the first element of the Array, which then increments to next element. a++;
why thewhen i see no int being returnedCode:int slow_print()
Last edited by Auxilium; 05-17-2011 at 04:37 PM.
Ok...Not gonna use it, but ok.
Unless people are completely retarded, they can see how it all works. It's written in human readability not in machine code. Besides, i comment what the functions/etc are for, so people know it, and can figure out the rest.
The slow_print function was something i made it to, to let me add more features, in the future
Please keep in mind, this is kind of my second time using Arrays. Thus it being a long time ago, i learned about them. I've never actually had a use of them, before now
2nd time using Arrays... ok...
Light travels faster than sound. That's why most people seem bright until you hear them speak.