Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Force Buffer Usage cout

Posted on 2006-04-10
11
Medium Priority
?
654 Views
Last Modified: 2012-06-21
Hi, how can I set my cout statements to a forced buffer?
In other words, how can I stop it from drawing until flushed?
0
Comment
Question by:List244
  • 7
  • 4
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16419187
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
 
LVL 86

Expert Comment

by:jkr
ID: 16419194
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
 
LVL 8

Author Comment

by:List244
ID: 16419286
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:jkr
ID: 16419359
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
 
LVL 8

Author Comment

by:List244
ID: 16419512
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
 
LVL 86

Expert Comment

by:jkr
ID: 16419739
>>Because I would have to buffer a single character and then print.

How are you doing the 'color thing' exactly at the moment?
0
 
LVL 8

Author Comment

by:List244
ID: 16419750
I am using SetConsoleTextAttribute, then I am printing out the character.
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 16419880
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
 
LVL 86

Expert Comment

by:jkr
ID: 16423146
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
 
LVL 8

Author Comment

by:List244
ID: 16423153
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
 
LVL 86

Expert Comment

by:jkr
ID: 16423161
Take you time, I just re-read it and simply didn't like it *g*
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question