At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
Is there an easy way to accomplish this task?
Thank you in advance!
Cheers
Stefano 5 5892
StephQ wrote:
At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
What about returning a std::string? You could send that to cout or a file
using <<. So it seems to fit the description.
Alternatively, you could also make your function use an ostream & instead of
a ofstream &.
Best
Kai-Uwe Bux
On Mar 6, 1:39 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
StephQ wrote:
At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
What about returning a std::string? You could send that to cout or a file
using <<. So it seems to fit the description.
Alternatively, you could also make your function use an ostream & instead of
a ofstream &.
Best
Kai-Uwe Bux
See my reply above.
I have never used ostream before. Do you have a link to a reference /
tutorial about it and streams in general?
Best
StephQ
StephQ wrote:
On Mar 6, 1:39 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
>StephQ wrote:
At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
What about returning a std::string? You could send that to cout or a file using <<. So it seems to fit the description.
Alternativel y, you could also make your function use an ostream & instead of a ofstream &.
Best
Kai-Uwe Bux
See my reply above.
See my reply to that reply.
I have never used ostream before. Do you have a link to a reference /
tutorial about it and streams in general?
Unfortunately, computer books are incredibly booring to me (with very,
_very_ few exceptions). I don't read them unless I have to look up
something. For that, I usually refer to the C++ standard. However, it
appears to be general consensus in this forum that this is not a good
recommendation.
However, for the case you mentioned, I take it that you have some function
void log ( std::ofstream & the_stream ) {
...
}
I would try to just changing it to
void log ( std::ostream & the_stream ) {
// same body
}
Unless you use file-specific methods (for which I don't see a need), you
should get away with that small change.
Best
Kai-Uwe Bux
"Kai-Uwe Bux" <jk********@gmx .netwrote in message
news:es******** @murdoch.acc.Vi rginia.EDU...
StephQ wrote:
>On Mar 6, 1:39 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
>>StephQ wrote: At the moment I have a void member function (of a given class) that takes as input an obj of class type ofstream and write some debug information to it using the << operator. I would like to modify the code so that the function returns a "stream" that can be "sent" to cout or to a file using <<, as this would give me more flexibility. I used " " because I'm not sure I'm not using the correct terms here. :P
What about returning a std::string? You could send that to cout or a file using <<. So it seems to fit the description.
Alternatively , you could also make your function use an ostream & instead of a ofstream &.
Best
Kai-Uwe Bux
See my reply above.
See my reply to that reply.
>I have never used ostream before. Do you have a link to a reference / tutorial about it and streams in general?
Unfortunately, computer books are incredibly booring to me (with very,
_very_ few exceptions). I don't read them unless I have to look up
something. For that, I usually refer to the C++ standard. However, it
appears to be general consensus in this forum that this is not a good
recommendation.
However, for the case you mentioned, I take it that you have some function
void log ( std::ofstream & the_stream ) {
...
}
I would try to just changing it to
void log ( std::ostream & the_stream ) {
// same body
}
Unless you use file-specific methods (for which I don't see a need), you
should get away with that small change.
Umm.. I don't see a change. I think you meant to change it to:
std::ostream& log ( std::ostream& the_stream ) {
// same body
return the_stream;
}
didnt' you?
>
Best
Kai-Uwe Bux
Jim Langston wrote:
>
"Kai-Uwe Bux" <jk********@gmx .netwrote in message
news:es******** @murdoch.acc.Vi rginia.EDU...
>StephQ wrote:
>>On Mar 6, 1:39 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote: StephQ wrote: At the moment I have a void member function (of a given class) that takes as input an obj of class type ofstream and write some debug information to it using the << operator. I would like to modify the code so that the function returns a "stream" that can be "sent" to cout or to a file using <<, as this would give me more flexibility. I used " " because I'm not sure I'm not using the correct terms here. :P
What about returning a std::string? You could send that to cout or a file using <<. So it seems to fit the description.
Alternativel y, you could also make your function use an ostream & instead of a ofstream &.
Best
Kai-Uwe Bux
See my reply above.
See my reply to that reply.
>>I have never used ostream before. Do you have a link to a reference / tutorial about it and streams in general?
Unfortunatel y, computer books are incredibly booring to me (with very, _very_ few exceptions). I don't read them unless I have to look up something. For that, I usually refer to the C++ standard. However, it appears to be general consensus in this forum that this is not a good recommendation .
However, for the case you mentioned, I take it that you have some function
void log ( std::ofstream & the_stream ) { ... }
I would try to just changing it to
void log ( std::ostream & the_stream ) { // same body }
Unless you use file-specific methods (for which I don't see a need), you should get away with that small change.
Umm.. I don't see a change. I think you meant to change it to:
std::ostream& log ( std::ostream& the_stream ) {
// same body
return the_stream;
}
didnt' you?
No, I did not. Rereading what I wrote, I find that I changed exactly what I
meant to change. You just missed it. Hint: I removed just one letter!
Best
Kai-Uwe Bux This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Rock |
last post by:
I already found an alternative way to accomplish this (using
ReadBytes), still I'd like to understand why I'm getting and error
reading a text file using the following method. The exception is
returned on the ReadString call.
public string BinaryRead(string fileName)
{
FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
|
by: Claus - Arcolutions |
last post by:
I got a word document as a stream, and I want to get the text from the word
document. But I cant seem to find anything to use for that purpose.
The "Microsoft office ?.object" com reference, only include functionality to
read from a file (as far as I know).
I looked a little on the structure of the document, but it doesnt seem to
have any common structures, especially not if you compare from different
office versions.
|
by: Michael Stock |
last post by:
Hi all,
hopefully someone can tell me how to do this for a web
server in C#:
We have images in a folder you can't access over the net.
So everytime we need to display an image from this folder,
we need to us the following syntax:
<img src="viewImage.aspx?imageID=/secretImages/image.jpg"
border="0">
|
by: CVerma |
last post by:
I'm using an html input control
(System.web.UI.HTMLControls.HTMLInputFile) to upload files such as
msword, excel, jpg, and pdf.
I have the encType property set in the form:
encType="multipart/form-data"
<INPUT id="UploadFile" type="file" name="UploadFile" runat="server">
Private Sub btnUploadFile_Click(ByVal sender As System.Object, ByVal e
|
by: semedao |
last post by:
Hi,
I am using cryptostream on both sides on tcp connection that pass data.
I am also use asyc socket , so , the data that recieved in the callback
method not always have the length of the buffer I sent.
for ex
I want to send 10000 bytes
I can get it in 10 times of 1000 bytes each.
so , I need to know when I complete the receiving , I want to write inside
cryptostream and check the position compare it to the length I already know
I...
| |
by: chandanlinster |
last post by:
When I was reading the man-page of fflush, I came across this statement
---
"The function fflush forces a write of all user-space buffered data for
the given output or update stream via the stream's underlying write
function."
what exactly is an "update stream"?
|
by: StephQ |
last post by:
At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
Is there an easy way to...
|
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= |
last post by:
Hello,
(sorry to begin with Java in a Python list ;-)
in Java, when I want to pass input to a function, I pass
"InputStream", which is a base class of any input stream.
In Python, I found that "file" objects exist. While specifying
argument types in Python is not possible as in Java, it is possible to
check whether an object is an instance of some class and that's what I
need - I need to check if an argument is a "file"-like object,...
|
by: RobUK |
last post by:
We have Apache on the local network managing several websites that are accessed using virtual domains (configured in the local machine's hosts file, eg. 192.168.1.10 points to dev.somedomain.com).
I am reworking the way that I access images on the site by specifying the http://etc address of the image instead of the local relative address. This is so that I can eventually have a separate server serving images to all websites (a lot of images...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |