468,512 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

what's the difference betwwen these two ways to use std::ofstream

//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::wstring file, std::ios_base::openmode mode /*undefined
too, why?*/){}
private:
std::ofstream out; //error c2079, uses undefined class
'std::basic_ofstream<_Elem, _Traits>'
}

btw, how to use ios_base:openmode? is it declared in std namespace?

Aug 24 '06 #1
2 5432

"thinktwice" <me*********@gmail.comskrev i meddelandet
news:11********************@m73g2000cwd.googlegrou ps.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
<fstreamheader?

//case 2, declare it in a class
class Logger
{
public:
Logger(std::wstring file, std::ios_base::openmode mode
/*undefined
too, why?*/){}
private:
std::ofstream out; //error c2079, uses undefined class
'std::basic_ofstream<_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:openmode? 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
Aug 24 '06 #2
thanks Persson , you are right,
i do include <fstreamin cpp file.
and the function implementation and the class definination is in the
header file.

Aug 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by red floyd | last post: by
3 posts views Thread by Chase Bradford | last post: by
6 posts views Thread by ma740988 | last post: by
11 posts views Thread by Gurikar | last post: by
3 posts views Thread by magix | last post: by
15 posts views Thread by aaragon | last post: by
2 posts views Thread by Dave Johansen | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.