| | |
buffer cout output and modify cout output order
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
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)
#include <iostream> using namespace std; int main (void) { cout << "cout output until this point"; string BUFFER; // I need to buffer the cout output until now. cout << "Content-length: " + BUFFER.length(); // cout this first. cout << BUFFER; // cout the BUFFER after the: Content-length. cout.flush(); // Is this necessary? return 0; }
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 263
0
#2 Oct 23rd, 2009
"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.
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.
Klatu Barada Nikto
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
0
#3 Oct 23rd, 2009
Last edited by raigs; Oct 23rd, 2009 at 5:54 pm.
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
0
#6 Oct 23rd, 2009
•
•
•
•
Try another example so we can understand better what you are trying to do.
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)
#include <iostream> using namespace std; int main (void) { cout << "cout output until this point"; string BUFFER; // I need to buffer the cout output until now. cout << "Content-length: " << BUFFER.length(); // Then, cout the size of the buffer. cout << BUFFER; // Then, cout that buffer's content. return 0; }
![]() |
Similar Threads
- cout types (C++)
- function changing order while executing program!!! (C++)
- Building output 1 character at a time (C++)
- After 2nd element read... cout is "scattered" (C++)
- Output 2D array? (C++)
- problem printing output (C++)
- Homework Help, please... [cout, cin] (C++)
- transfer input.txt to output.txt help prz (C++)
Other Threads in the C++ Forum
- Previous Thread: error trap
- Next Thread: finding icons and manipulating their x,y values?
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






