Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what's the difference betwwen these two ways to use std::ofstream

Reply
Thread Tools

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

 
 
thinktwice
Guest
Posts: n/a
 
      08-24-2006
//case 1, works fine
function(..)
{
std:fstream 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:penmode mode /*undefined
too, why?*/){}
private:
std:fstream out; //error c2079, uses undefined class
'std::basic_ofstream<_Elem, _Traits>'
}

btw, how to use ios_basepenmode? is it declared in std namespace?

 
Reply With Quote
 
 
 
 
Bo Persson
Guest
Posts: n/a
 
      08-24-2006

"thinktwice" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed) ps.com...
> //case 1, works fine
> function(..)
> {
> std:fstream out;
> out.open(file);
> out << "error info" <<endl;
> out.close();
> }


Just a guess: The function is in a cpp file that includes the
<fstream> header?


> //case 2, declare it in a class
> class Logger
> {
> public:
> Logger(std::wstring file, std::ios_base:penmode mode
> /*undefined
> too, why?*/){}
> private:
> std:fstream 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_basepenmode? is it declared in std namespace?
>


It is. There is a header <ios> that contains a lot of types and
constants used by the stream classes.


Bo Persson


 
Reply With Quote
 
 
 
 
thinktwice
Guest
Posts: n/a
 
      08-25-2006
thanks Persson , you are right,
i do include <fstream> in cpp file.
and the function implementation and the class definination is in the
header file.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exchanging data betwwen threads? Solang C++ 3 09-20-2009 05:55 PM
Difference between two ways to set Text in a TextBox ? Moe Sisko ASP .Net 0 03-31-2008 05:59 AM
How copy dir when there is a space betwwen cyrusgreats@gmail.com Perl Misc 2 06-22-2007 05:10 PM
the difference among these ways of swapping two ints storyGerald@gmail.com C++ 9 11-21-2005 12:32 PM
What's the difference betwwen explicit instantiaion and explicit specialization? Andy C++ 5 01-30-2005 11:46 PM



Advertisments