I have a computer game that has no console. If I want to output something I
push a string to the back of a std::vector<std::stringand that gets output
and maintained.
All is well and good, but what I would like to do is to be able to use
ostream's power for this output. I could create my own ostream and check it
every cycle or something, but then I would have to pass this ostream or make
it global.
What I would like to do is have something like:
std::cout << "Player " << ThisPlayer.Name() << " logged in at: " << time()
<< "\n";
and have that get redirected, somehow, to my vector.
If no one has an easy way to do this I'll have to go with the global ostream
approach and pull everything out of it every cycle. 3 6643
Jim Langston wrote:
I have a computer game that has no console. If I want to output something
I push a string to the back of a std::vector<std::stringand that gets
output and maintained.
All is well and good, but what I would like to do is to be able to use
ostream's power for this output. I could create my own ostream and check
it every cycle or something, but then I would have to pass this ostream or
make it global.
What I would like to do is have something like:
std::cout << "Player " << ThisPlayer.Name() << " logged in at: " << time()
<< "\n";
and have that get redirected, somehow, to my vector.
Write a streambuf that appends to the vector, then replace cout's one with
that.
Jim Langston schrieb:
I have a computer game that has no console. If I want to output something I
push a string to the back of a std::vector<std::stringand that gets output
and maintained.
All is well and good, but what I would like to do is to be able to use
ostream's power for this output. I could create my own ostream and check it
every cycle or something, but then I would have to pass this ostream or make
it global.
What I would like to do is have something like:
std::cout << "Player " << ThisPlayer.Name() << " logged in at: " << time()
<< "\n";
and have that get redirected, somehow, to my vector.
If no one has an easy way to do this I'll have to go with the global ostream
approach and pull everything out of it every cycle.
I found a nice solution here: http://groups.google.com/group/borla...c46e2bfaaa6cbc
---------
ostringstream output;
// set cout's streambuf to be the ostringstream's streambuf
cout.rdbuf(output.rdbuf());
---------
--
Thomas
"Thomas J. Gritzan" <Ph*************@gmx.dewrote in message
news:eb**********@newsreader2.netcologne.de...
Jim Langston schrieb:
>I have a computer game that has no console. If I want to output something I push a string to the back of a std::vector<std::stringand that gets output and maintained.
All is well and good, but what I would like to do is to be able to use ostream's power for this output. I could create my own ostream and check it every cycle or something, but then I would have to pass this ostream or make it global.
What I would like to do is have something like:
std::cout << "Player " << ThisPlayer.Name() << " logged in at: " << time() << "\n";
and have that get redirected, somehow, to my vector.
If no one has an easy way to do this I'll have to go with the global ostream approach and pull everything out of it every cycle.
I found a nice solution here:
http://groups.google.com/group/borla...c46e2bfaaa6cbc
---------
ostringstream output;
// set cout's streambuf to be the ostringstream's streambuf
cout.rdbuf(output.rdbuf());
---------
--
Thomas
Thanks. That's exactly the type of thing I was looking for and will work
perfectly. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Trevor |
last post by:
Hello,
Please bear with me, I am trying to learn C++. I am implementing some
error/debug functions which format a message and output it to a C++ stream.
I would like to design it using one low...
|
by: Massimiliano Alberti |
last post by:
Can I specialize a template function in a subclass without overriding
it? (the main template function is defined in a base class).
Now I'm doing something like that:
(in base class)...
|
by: GGG |
last post by:
I have a situation where at tool is passing me a large array of
strings that I need to process in a particular type of data. Each item
in the array gets to me as a pair of std::strings, basically,...
|
by: Dylan |
last post by:
What advantages does std::cerr offer over std::cout?
(I'm trying to understand why it exists)
thanks
|
by: Rick N. Backer |
last post by:
Hello folks,
Novice type question here.
I'm working with a very simple app here that takes a series of strings
from the console. Once the end user has finished inputting the
strings they are...
| |
by: Cliff Martin |
last post by:
Hi,
I am writing a simple filter type program that can take input from
file or stdin, and output to a file or stdout. It would make life much
easier if I could assign cin to a ifstream object...
|
by: arnuld |
last post by:
I have 2 programs.
1st PROGRAM: copies an input file to standard output but it
does so at the expense of deleting all white-space
(space, tabs, newlinies etc).
2nd PROGRAM: copies the input...
|
by: Miles |
last post by:
Hello all,
When I subclass std::exception and throw an instance of the subclass,
when I call the what() method of the caught exception, it does not
call the overridden method. I'm under the...
|
by: Adrian |
last post by:
Is it possible to save a copy of cout the same way you can save a copy
of stdout in C (I know C version is portable, but unix portable is
good enough for me).
I have to use a library which...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |