944,175 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 707
  • C++ RSS
Oct 23rd, 2009
0

buffer cout output and modify cout output order

Expand Post »
N00B. Can I buffer cout, cout something and then cout the buffer? I've been googleing but did not find anything of this sort.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (void)
  6. {
  7. cout << "cout output until this point";
  8.  
  9. string BUFFER; // I need to buffer the cout output until now.
  10.  
  11. cout << "Content-length: " + BUFFER.length(); // cout this first.
  12.  
  13. cout << BUFFER; // cout the BUFFER after the: Content-length.
  14.  
  15. cout.flush(); // Is this necessary?
  16.  
  17. return 0;
  18. }
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
raigs is offline Offline
25 posts
since Oct 2009
Oct 23rd, 2009
0
Re: buffer cout output and modify cout output order
"Content-length: "
That is a string and this:
BUFFER.length()
equates to an int. So when you use the + operator between the two are you trying to concatenate an int onto the string or are you trying to add an int to a string or are what are you trying to do? You could output both like this:

cout << "Content-length: ";
cout << BUFFER.length();

but everything between the << and ; operators in this line:

cout << "Content-length: " + BUFFER.length();

is considered one object so it has to be compatible one way or the other.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Oct 23rd, 2009
0
Re: buffer cout output and modify cout output order
Click to Expand / Collapse  Quote originally posted by Lerner ...
"Content-length: "
That is a string and this:
BUFFER.length()
equates to an int.
Yes, I made a mistake by concatenating a string and an integer when I drew up that example.

But how can I buffer cout and modify the order they are output?
Last edited by raigs; Oct 23rd, 2009 at 5:54 pm.
Reputation Points: 9
Solved Threads: 0
Light Poster
raigs is offline Offline
25 posts
since Oct 2009
Oct 23rd, 2009
0
Re: buffer cout output and modify cout output order
Try another example so we can understand better what you are trying to do.

This:
cout << 4 + 7;
works fine as does this:
string word1 = "hello";
string word2 = " world";
cout << word1 + word2;

but I'm not sure what you are thinking about.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Oct 23rd, 2009
0
Re: buffer cout output and modify cout output order
-
Last edited by raigs; Oct 23rd, 2009 at 7:08 pm. Reason: double post
Reputation Points: 9
Solved Threads: 0
Light Poster
raigs is offline Offline
25 posts
since Oct 2009
Oct 23rd, 2009
0
Re: buffer cout output and modify cout output order
Click to Expand / Collapse  Quote originally posted by Lerner ...
Try another example so we can understand better what you are trying to do.
1. How can I store all the output into a buffer?
2. Then, I have to get the size of that buffer and cout a string stating that buffer's size. How can I achieve this?
3. Then, cout that buffer's content.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (void)
  6. {
  7. cout << "cout output until this point";
  8.  
  9. string BUFFER; // I need to buffer the cout output until now.
  10.  
  11. cout << "Content-length: " << BUFFER.length(); // Then, cout the size of the buffer.
  12.  
  13. cout << BUFFER; // Then, cout that buffer's content.
  14.  
  15. return 0;
  16. }
Reputation Points: 9
Solved Threads: 0
Light Poster
raigs is offline Offline
25 posts
since Oct 2009

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: error trap
Next Thread in C++ Forum Timeline: finding icons and manipulating their x,y values?





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


Follow us on Twitter


© 2011 DaniWeb® LLC