944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5534
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
May 30th, 2006
0

cout is too slow

Expand Post »
I am extremely new to C++, can sum1 tell me a faster way to output stuff than cout? It either outputs too slow or takes too long to automatically scroll or something. I was trying to sort of output and refresh in real time w cout
Similar Threads
Reputation Points: 23
Solved Threads: 2
Light Poster
LieAfterLie is offline Offline
38 posts
since May 2006
May 30th, 2006
0

Re: cout is too slow

Can you explain a bit more on what you are trying to do? Better if you can post the code. Otherwise there will be a lot of answers based on a lot of assumptions.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
May 30th, 2006
0

Re: cout is too slow

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.
Reputation Points: 23
Solved Threads: 2
Light Poster
LieAfterLie is offline Offline
38 posts
since May 2006
May 30th, 2006
0

Re: cout is too slow

Wow, i need to read what I write before i post. If anyone wants, i can email it so you can see what i mean.
Reputation Points: 23
Solved Threads: 2
Light Poster
LieAfterLie is offline Offline
38 posts
since May 2006
May 30th, 2006
0

Re: cout is too slow

No need to email. You can attach your program here. Make sure you attach code, and not the executable.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
May 30th, 2006
0

Re: cout is too slow

Fancy. Ty. Its like 1008 lines and not well commented, though. Atleast it only uses simple stuff.
Attached Files
File Type: cpp 15puzzle.cpp (31.0 KB, 67 views)
Reputation Points: 23
Solved Threads: 2
Light Poster
LieAfterLie is offline Offline
38 posts
since May 2006
May 30th, 2006
0

Re: cout is too slow

Skimmed through your program, and it is not 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)
  1. for ( i = 0 ; i < 50; i++ )
  2. cout << '\n';
This piece of code calls 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)
  1. std::string newline( 50, '\n');
  2. std::cout << newline ;
Clean up your code like that, and you will get to know more modifications where you can make the code fast.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
May 30th, 2006
0

Re: cout is too slow

thanks. I don't know how to apply it, though.... Im new. I dont even know what std:: and that newline function do. (sry)
Reputation Points: 23
Solved Threads: 2
Light Poster
LieAfterLie is offline Offline
38 posts
since May 2006
May 30th, 2006
0

Re: cout is too slow

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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
May 30th, 2006
0

Re: cout is too slow

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: mid-chapter exercise inquiry - compile 2 files @ once?
Next Thread in C++ Forum Timeline: constructor with an array as an argument





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC