|
I have created a new stream, which looks like this:
template <class charT, class traits>
class basic_osLogFile : public std::basic_streambuf<charT, traits>
{
...
}
What I want to do is create a class that encapsulates this, so I can easily go:
osLogFile f("c:\\Errors");
f << "error number " << nError << endl;
f.close();
I've tried this:
class osLogFile : public std::ostream
{
public:
osLogFile() : ostream(&msb),ios(0) {}
virtual ~osLogFile() { msb.pubsync(); }
private:
basic_osLogFile<char, std::char_traits<char> > msb;
};
but the errors are:
c:\my code\iostreams\testapp\debugstr\\debugstream.h(68) : error C2512: 'basic_ostream<char,struct std::char_traits<char> >' : no appropriate default constructor available
c:\my code\iostreams\testapp\debugstr\\debugstream.h(68) : error C2614: 'osLogFile' : illegal member initialization: 'ios' is not a base or member
c:\my code\iostreams\testapp\debugstr\\debugstream.h(68) : error C2614: 'osLogFile' : illegal member initialization: 'ostream' is not a base or member
Does anyone have any suggestions ?
Thanks.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
<i>And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned.</i> - <b>Christopher Duncan - 18/04/2002</b>
|
|
|
|
|
Hi CG,
This compiles fine on my PC:
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248d
using namespace std;
template<class charT, class T = char_traits<charT> ᡊe9ac73-238b-46be-991d-0f050c37248dclass basic_osLogFile : public std::basic_streambuf<charT, Tᡊe9ac73-238b-46be-991d-0f050c37248d{
};
void main()
{
basic_osLogFile<char> t;
}
Maxwell Chen
Lets make bugs better!
|
|
|
|
|
*just rewording this so it does not sound rude* While that works, if you try operator <<, you'll find it is undefined, the stream object is useless.
I need to derived my stream from basic_streambuf, but to create an instance of it, I need to derive from ostream. I can do this:
basic_osLogFile<char> t;
ostream s(t);
but I'd prefer something a little less ugly, which means creating an ostream that can be instantiated as easily as ofstream, but which uses my streambuf.
Do you have any ideas ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
*just rewording this so it does not sound rude* While that works, if you try operator <<, you'll find it is undefined, the stream object is useless.
That's OK, I like step-by-step!
I don't know the details about stream and the hierarchy (haven't pay time to read it), I tried to read your msgs again, this compiles fine:
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248d#include <fstreamᡊe9ac73-238b-46be-991d-0f050c37248d
using namespace std;
template<class charT, class T = char_traits<charT> ᡊe9ac73-238b-46be-991d-0f050c37248dclass basic_osLogFile : public std::basic_streambuf<charT, Tᡊe9ac73-238b-46be-991d-0f050c37248d{
};
class osLogFile : public std::ostream
{
public:
osLogFile() : ostream(&msb),ios(0) {}
virtual ~osLogFile() { msb.pubsync(); }
private:
basic_osLogFile<char> msb;
};
void main()
{
osLogFile s;
s << "Hello";
}
Maxwell Chen
Lets make bugs better!
|
|
|
|
|
You're right - but it only works if I use 'using namespace std' ( which I never do ).
I think if I use std within my own namespace, that might solve my problem somewhat....
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Try this:
class osLogFile : public std::ostream
{
typedef std::ostream ostream;
typedef std::ios ios;
public:
osLogFile() : ostream(&msb),ios(0) {}
...
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I did, I get this:
c:\my code\iostreams\testapp\debugstr\\debugstream.h(83) : error C2629: unexpected 'class osLogFile ('
c:\my code\iostreams\testapp\debugstr\\debugstream.h(83) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
I've made no other changes. replacing the two new lines with a global using namespace std will compile just fine. Obviously I would never do that, but I'm toying with doing it within a namespace I define, and then using mynamespace::osLogFile. would koenig lookup mean that this would pull all of std into the global namespace ?
Obviously if we can get your initial suggestion to work, then that won't matter either way.
Thanks for the help.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Hmmm... this little pesky compiler isn't behaving, I guess. My suggestion comes from a very similar problem I had in the past. My final solution was like this:
namespace sockiostr{
class socketstream: public std::iostream, noncopyable
{
private:
typedef std::iostream super;
public:
socketstream():
super(&sockbuf),
sockbuf()
{}
... and it indeed works.
PS. Of course, in your case the compliant syntax would be
class osLogFile : public std::ostream
{
public:
osLogFile() : std::ostream(&msb),std::ios(0) {}
... but this won't work in VC++ 5.0 --have you given it a try in VC++ 6.0?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
noncopyable ? Is that another base ?
Anyhow, it accepts the typedef syntax IF I use namespace std as well, but without using namespace std, it blows up. I guess I'll put it in a namespace and experiment to see if namespace std remains in place when I use it.
Thanks for the help though.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
noncopyable ? Is that another base ?
Yes it is. I copied and pasted from the original source without any modification. I guess the purpose of this base class is obvious, anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Off-topic, your explicit construction ios(0) clashes with (and takes precedence over) ostream(&msb) . I guess you should omit it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the tip. I'm still pretty new at this... Actually I'm writing this to prove to some people at work that doing it with iostreams will be better than using C style string handling, so any tips that make it 'right' are very much appreciated.
Thanks again
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Does anyone know of any articles regarding the creation of a compiled component that I can call from regular ASP through this method:
dim obj
Set obj = Server.CreateObject("...")
obj.CreateGraphics(...)
set obj = nothing
I would like to write a graphics function that I will be able to call within ASP. Any help would be great. Thanks in advance.
Nick Parker
|
|
|
|
|
Yes, it's a COM component, almost always created with ATL.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Thanks Christian, I have been looking for something online but it looks like I may need to create something myself. I haven't been able to find a damn bit about Polar charts in OWC. I think I found an article on CodeGuru for this[ATL Components], but thought I would get everyone else's opinions first. Thanks agian.
Nick Parker
|
|
|
|
|
If you don't have time to learn ATL, you can use VB 6 to create COM DLLs. I haven't done that, but I do believe it should be an easy process.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
I would like to learn ATL, really, I need to create graphics and we don't have the GDI available in VB 6. Any other ideas Nish? Thanks
Specs:
I only need to be able to draw one line, the direction the line points will be given in degrees, and I also need to label the endpoints to the line. Once this is done, I just need to save it as an image.
Nick Parker
|
|
|
|
|
Nick Parker wrote:
would like to learn ATL, really, I need to create graphics and we don't have the GDI available in VB 6. Any other ideas Nish? Thanks
Specs:
I only need to be able to draw one line, the direction the line points will be given in degrees, and I also need to label the endpoints to the line. Once this is done, I just need to save it as an image.
Well, ATL is not easy to start with. I mean unlike C# or VB you can't start coding in 2 days time. It takes time to dig in.
And if all you want to do is draw a line, I am sure VB has some line drawing functions.
But then ATL is sorta fun once you get the hang of it. I am still a sorta ATL newbie. I keep trying to find some time for learning it well, but never got the chance and then I am also lazy
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
|
I'm writing a database program accessing access2000.
"pRs->update() "is done,the message"IDispatch 3105"appear.
Who will help me?Why my Recordset is not be updated?Where i'll find the archive for solving ado error code?Thanks.
|
|
|
|
|
Most error codes can be found by searching TechNet.
|
|
|
|
|
I've tried to convert integers to numbers but it hasn't been working for me. I was wondering if there was just any way I could just enter characters into a matrix without having to convert integers to characters. Thanks. nywebhead@hotmail.com
|
|
|
|
|
What do you mean by integers to numbers ? Do you mean convert a number to a string ? ostringstreams will do that for you ( read my article ). Do you mean convert a string to a number ? atoi does that. An integer IS a number, so I don't know what you're meaning to ask.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Sorry, I ment I've tried to convert integers to characters. I've been working on that, but it hasn't gotten the job I need done, done. What I mena is, is there any way characters can be entered into a matrix? Sorry, my last post incorrectly.
|
|
|
|
|
A matrix is best represented by a two dimensional array, or a vector of vectors.
Integers to characters - you need to look at my ostringstream article. It also explains sprintf, the more common solution, and why it is of the devil. If you're using MFC, CString::Format will do the job nicely.
CString s;
s.Format ("Now theres %d green bottles, hangin' on the wall", 10);
AfxMessageBox(s);
The message box will report 10 green bottles on the wall.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|