473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IO Stream Library usage

Compiling this file produces the "no appropriate default constructor available" error
shown below. Can anyone explain why I'm getting this error and how to fix it???

This source file has been reduced to the bare essentials to reproduce the error.

/* test.cpp */
#include <ostream>

class LogStream : public std::ostream, public std::streambuf
{
public:
LogStream ();
};

LogStream :: LogStream ()
{
init(this);
};
/* end of test.cpp */

------ Build started: Project: test, Configuration: Debug Win32 ------

Compiling...
test.cpp
\Projects\test\ test99\test.cpp (10) : error C2512: 'std::basic_ost ream<_Elem,_Tra its>' :
no appropriate default constructor available
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]

Build log was saved at "file://d:\Projects\tes t\test99\test\D ebug\BuildLog.h tm"
test - 1 error(s), 0 warning(s)
---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped
Nov 17 '05 #1
4 1035
Joe Greene wrote:
Compiling this file produces the "no appropriate default constructor available" error
shown below. Can anyone explain why I'm getting this error and how to fix it???

This source file has been reduced to the bare essentials to reproduce the error.

/* test.cpp */
#include <ostream>

class LogStream : public std::ostream, public std::streambuf
{
public:
LogStream ();
};

LogStream :: LogStream ()
{
init(this);
};


ostream has no default constructor. In addition, you shouldn't ever call
init yourself if you are deriving from ostream, since ostream does it
for you (calling it twice causes a memory leak at the very least).

Needs to be something like:
LogStream::LogS tream()
:std::ostream(0 ) //calls init(0)
{
rdbuf(this); //reset streambuf
clear(); //clear badbit set by calling init(0)
}

Or you should reorder the base classes so that the streambuf is created
before the ostream:
class LogStream : public std::streambuf, public std::ostream
{
public:
LogStream ();
};
LogStream::LogS tream()
:std::ostream(t his) //calls init
{
}

Tom
Nov 17 '05 #2
Tom,
Thank you very much! That eliminated my compile error. Do you know a good book
to recommend that covers the standard IO Streams in depth?

Thanks again,
Joe

In article <e2************ **@TK2MSFTNGP12 .phx.gbl>, to********@hotm ail.com says...
Joe Greene wrote:
Compiling this file produces the "no appropriate default constructor available" error
shown below. Can anyone explain why I'm getting this error and how to fix it???

This source file has been reduced to the bare essentials to reproduce the error.

/* test.cpp */
#include <ostream>

class LogStream : public std::ostream, public std::streambuf
{
public:
LogStream ();
};

LogStream :: LogStream ()
{
init(this);
};


ostream has no default constructor. In addition, you shouldn't ever call
init yourself if you are deriving from ostream, since ostream does it
for you (calling it twice causes a memory leak at the very least).

Needs to be something like:
LogStream::LogS tream()
:std::ostream(0 ) //calls init(0)
{
rdbuf(this); //reset streambuf
clear(); //clear badbit set by calling init(0)
}

Or you should reorder the base classes so that the streambuf is created
before the ostream:
class LogStream : public std::streambuf, public std::ostream
{
public:
LogStream ();
};
LogStream::LogS tream()
:std::ostream(t his) //calls init
{
}

Tom

Nov 17 '05 #3
Joe Greene wrote:
Tom,
Thank you very much! That eliminated my compile error. Do you know a good book
to recommend that covers the standard IO Streams in depth?


The comprehensive text is "C++ IOStreams and Locales" by Langer and
Kreft. Apparently it's good, but I haven't read it personally.
Alternatively there are books on the whole of standard C++ or the whole
C++ standard library that cover it in less detail, such as "The C++
Standard Library" by Josuttis - much of the IOStreams section was
written by Dietmar Kuehl, an expert who regularly posts on
comp.lang.c++.m oderated.

Finally, check out the book reviews on www.accu.org, which are more
reliable than those on, say, Amazon.

Tom
Nov 17 '05 #4
Tom,

Thanks once again. And a special thanks for the pointer to www.accu.org which looks
like a great resource that I wasn't aware of.

Joe

In article <#Z************ **@TK2MSFTNGP12 .phx.gbl>, to********@hotm ail.com says...
Joe Greene wrote:
Tom,
Thank you very much! That eliminated my compile error. Do you know a good book
to recommend that covers the standard IO Streams in depth?


The comprehensive text is "C++ IOStreams and Locales" by Langer and
Kreft. Apparently it's good, but I haven't read it personally.
Alternatively there are books on the whole of standard C++ or the whole
C++ standard library that cover it in less detail, such as "The C++
Standard Library" by Josuttis - much of the IOStreams section was
written by Dietmar Kuehl, an expert who regularly posts on
comp.lang.c++.m oderated.

Finally, check out the book reviews on www.accu.org, which are more
reliable than those on, say, Amazon.

Tom

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7066
by: gipsy boy | last post by:
Given a file descriptor (from a network socket, for instance), I want to have an iostream that reads/writes to it, so I can push and read data in the traditional way : sockStream << "<some stuff>" < "\r\n" How is this possible with the standard header files? I need this because my objects have xml'ed << operators, but now I can't figure...
18
5675
by: JG | last post by:
Does anyone know a standard (or supported on Linux, Mac, Win32) way to clear a read stream buffer (standard ANSI C file stream)? I would even settle for a platform specific way of doing it. And no, I know I can use direct low level I/O or non-buffered to do reads, but for my app, I need the buffering. I can implement myself, but this is...
4
26792
by: TT (Tom Tempelaere) | last post by:
Hey there, I need a string stream, but I can't find one in .NET. I thought StringWriter would derive from Stream, alas it doesn't do so. Which leads me to my next question: What is the purpose of System.IO.StringWriter (or, what is its added value)??? It can do the same things with StringBuilder, and I see no added value. The reason...
8
2936
by: Eric Anderson | last post by:
I have some files that sit on a FTP server. These files contain data stored in a tab-separated format. I need to download these files and insert/update them in a MySQL database. My current basic strategy is to do the following: 1) Login to the ftp server using the FTP library in PHP 2) Create a variable that acts like a file handle using...
8
10417
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists on closing my stream, and I can't convince it not to. A much-simplified example is below; basically, as soon as the writer is disposed (marked...
4
2025
by: Helge Jensen | last post by:
In C# 2.0 System.IO.Stream is declared as: public class Stream: ..., IDisposable { ... public void Dispose(); public void Dispose(bool); IDisposable.Dispose(); } Which must be a design-blunder, if not a 100-year sleep. It prevents
87
5078
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for the library, and other resources related to managed strings are available for download from the CERT web site at: ...
9
3668
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in appropriately moved further down? From a cursory search of the libc documentation I can't find such a function. Will I have to write it myself? ...
7
9874
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script streams the file if the user is authorised. This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB file presents the error message...
0
7912
marktang
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...
0
7839
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...
0
8338
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
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...
0
5390
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...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.