//case 1, works fine
function(..)
{
std::ofstream out;
out.open(file);
out << "error info" <<endl;
out.close();
}
//case 2, declare it in a class
class Logger
{
public:
Logger(std::wst ring file, std::ios_base:: openmode mode /*undefined
too, why?*/){}
private:
std::ofstream out; //error c2079, uses undefined class
'std::basic_ofs tream<_Elem, _Traits>'
}
btw, how to use ios_base:openmo de? is it declared in std namespace? 2 5663
"thinktwice " <me*********@gm ail.comskrev i meddelandet
news:11******** ************@m7 3g2000cwd.googl egroups.com...
//case 1, works fine
function(..)
{
std::ofstream out;
out.open(file);
out << "error info" <<endl;
out.close();
}
Just a guess: The function is in a cpp file that includes the
<fstreamheade r?
//case 2, declare it in a class
class Logger
{
public:
Logger(std::wst ring file, std::ios_base:: openmode mode
/*undefined
too, why?*/){}
private:
std::ofstream out; //error c2079, uses undefined class
'std::basic_ofs tream<_Elem, _Traits>'
}
A class declaration if often in a .h file. If so, it must also include
the necessary headers for names it uses.
>
btw, how to use ios_base:openmo de? is it declared in std namespace?
It is. There is a header <iosthat contains a lot of types and
constants used by the stream classes.
Bo Persson
thanks Persson , you are right,
i do include <fstreamin cpp file.
and the function implementation and the class definination is in the
header file. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: m vaughn |
last post by:
I wanted to hold information about open files in a struct and be able
pass it around, but the behavior is not what I would expect. Can
someone tell me why this doesn't work? (Even better, what is the
proper way to do this, eg, without the pointers and such). As is
probably obvious, I am not terribly knowledgable here.
The *fs.of<< ... statement in main() does nothing in gcc 3.2.2 and
gives a seg fault in gcc 3.2 (Mandrake linux 9.1 and...
|
by: red floyd |
last post by:
Is there any way to retrieve the filename given to a std::ofstream
(passed in constructor or in ofstream::open())?
Or, should I derive from ofstream (should probably be a template to
handle ifstream and fstream as well, but I'm typing on the fly)
yes, I know the syntax may be off...
class onamedfstream : public ofstream {
|
by: Chase Bradford |
last post by:
Hey all
I have a class Foo, and I'm trying to overload the << operator for both
the ostream and ofstream for it. This way I should have two seperate
formats for output, one for files and another for the screen. Right now the
two declarations are:
std::ofstream& operator<<( std::ofstream &fos, const Foo &theClass);
std::ostream& operator<<( std::ostream &fos, const Foo &theClass);
|
by: ma740988 |
last post by:
There's no way to use the STL algorithm copy to print an outfile
(essentially an ofstream)? So now:
int main()
{
std::ifstream InFile( "exercise15.txt");
std::ofstream ToFile( "NewFile.txt" );
////////////////////////////
// Alternative 1
|
by: Gurikar |
last post by:
Hello,
ofstream ofs;
fun(char* str)
{
ofs<<str<<endl;
}
void main()
| |
by: davihigh |
last post by:
My Friends:
I am using std::ofstream (as well as ifstream), I hope that when i
wrote in some std::string(...) with locale, ofstream can convert to
UTF-8 encoding and save file to disk. So does ifstream.
Something I found shows that, I need to have a proper codecvt to set
it. I need more information, maybe a small piece of code sample. Thank
you!
|
by: magix |
last post by:
Hi,
I got following to savefile into Output.txt, but how can I specify it to be
in specific folder/directory (not at the same directory as the executables?
Currently, it will generate the output.txt under the same directory as the
executables.
std::stringstream stream;
stream << "Output.txt" << std::flush;
std::ofstream SaveFile(stream.str().c_str());
|
by: aaragon |
last post by:
Hello, does anyone have a clue about this error? and how to solve it?
It seems to be trivial to me, but not for the compiler. I'm using g++
4.2 on an Ubuntu Linux system:
// main()
....
std::ofstream fout;
fout.open("hello.out");
fout<<setfill('-')<<setw(20)<<"-"<<setfill(' ')<<endl;
fout<<"hello "; // this is line 139
|
by: Dave Johansen |
last post by:
Is it ok to call fcloseall() when using both C-style FILE * and C++
std::ofstream's to read files in a program?
Thanks,
Dave
|
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: 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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |