| | |
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,676
Reputation:
Solved Threads: 262
0
#2 34 Days Ago
"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 34 Days Ago
Last edited by raigs; 34 Days Ago at 5:54 pm.
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
0
#6 34 Days Ago
•
•
•
•
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 based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






