Force Buffer Usage cout

Hi, how can I set my cout statements to a forced buffer?
In other words, how can I stop it from drawing until flushed?
LVL 8
List244Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
I'd write to a stringstream and push that one to 'cout' when needed, e.g. like

#include <iostream>
#include <sstream>
using namespace std;

//...

stringstream ss;

ss << "Some text " << endl << "Some integer value " << 42 << " floating point " << 3.141 << endl;
// ... more

// and finally:

cout << ss.str();
0
jkrCommented:
BTW, an 'ostringstream' might be suitable even better, e.g.

ostringstream oss;

oss << "Some text " << endl << "Some integer value " << 42 << " floating point " << 3.141 << endl;
// ... more

// and finally:

cout << oss.str();
0
List244Author Commented:
The problem with that is my values are not normal.  I am using colored values which draw to the screen
and pretty much what I would like to do is clear out a little of the blinking when redrawing.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

jkrCommented:
That should work even for control characters. By 'buffering' the output, you'll write that when your done with all the formatting and the output, so you should get rid of the problem that way.
0
List244Author Commented:
My output has so many colors though, it would almost be the same.  Because I would have to buffer a single character and
then print.  My actual draw routine does not give too much flicker, my problem is when I clear and redraw.  My main problem
is I would like this clear function(self-written not system("cls")) not to register until it has been redrawn.

I could modify the clear function not to clear those areas in which will be drawn to pretty easily, but I was just curious if I could just
stop output until I was ready instead.
0
jkrCommented:
>>Because I would have to buffer a single character and then print.

How are you doing the 'color thing' exactly at the moment?
0
List244Author Commented:
I am using SetConsoleTextAttribute, then I am printing out the character.
0
jkrCommented:
Ah, I see. Then, I'd suggest to use multiple screen buffers for your console, do the writing to an 'inactive' one and then use 'SetConsoleActiveScreenBuffer()' to activate that one to complete the flicker and blinking completely. See e.g. http://windowssdk.msdn.microsoft.com/library/en-us/DllProc/base/reading_and_writing_blocks_of_characters_and_attributes.asp ("Reading and Writing Blocks of Characters and Attributes")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
Make "to activate that one to complete the flicker and blinking completely" read "to activate that one to eliminate the flicker and blinking completely" *grmpf* ;o)
0
List244Author Commented:
Haha, I knew what you meant, just give me a little while so I can actually try it out and see how it works.
I should be able to get to it tomorrow.
0
jkrCommented:
Take you time, I just re-read it and simply didn't like it *g*
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.