| | |
cout is too slow
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
its really big, prolly outside the limits for posts. Im getting way ahead of myself, making a program this big wen i know nothing and probably would be able to make the same program better if i wait until i know more. but, basically its a program for the 15 slider puzzle and it gets confusing/disorienting or watever cause the info is flashing too fast for you to really make moves as fsast as you would like.
Skimmed through your program, and it is not
This piece of code calls
A better way will be to first create the string with 50 newline characters and output them all in a single cout call. like this
Clean up your code like that, and you will get to know more modifications where you can make the code fast.
cout that seems to be the problem. You are calling cout too much. Remember that optimization of code should start first with your algorithm. The rest will usually be taken care by a decent compiler. Take for example the for loops where you are outputting 50 newline characters. C++ Syntax (Toggle Plain Text)
for ( i = 0 ; i < 50; i++ ) cout << '\n';
cout 50 times. IO functions take a lot of time. That means you are writting to the console 50 times which takes a lot of time, when you consider the total number of times you do this in your program.A better way will be to first create the string with 50 newline characters and output them all in a single cout call. like this
C++ Syntax (Toggle Plain Text)
std::string newline( 50, '\n'); std::cout << newline ;
newline is not a function. It is a string object. What
std::string newline( 50, '\n' ) does is, create a string called newline that has 50, '\n' characters. Since you have used using namespace std; at the beginning, you can just use string newline(50, '\n' );. You will have to use the #include <string> at the beginning. Then cout just outputs it. I suggest you get a good C++ book if you dont have one, and start reading about C++ strings to learn more. you may fine good tutorials in the internet too. It's not a good idea to write a GUI in the console window.
You can do it of course, but you'll run into all sorts of problems.
If you have a java enabled browser this may give you some ideas as well.
You can do it of course, but you'll run into all sorts of problems.
If you have a java enabled browser this may give you some ideas as well.
*Voted best profile in the world*
![]() |
Similar Threads
- Internet Explorer Running SLOW (Web Browsers)
- C++ cout statement (C++)
- This site going very very slow (DaniWeb Community Feedback)
- ASP slow-down server script (ASP)
Other Threads in the C++ Forum
- Previous Thread: mid-chapter exercise inquiry - compile 2 files @ once?
- Next Thread: constructor with an array as an argument
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






