------- Comment #4 from china dot wenli dot wang at gmail dot com  2010-08-10 
01:07 -------
(In reply to comment #3)
> (In reply to comment #2)
> > Thank you,yeah,the code is not a self-contained testcase.I copile it with
> > another codes which not show here.
> 
> Yes, but we don't want to see a useless chunk of your program, it doesn't help
> anyone. You could have reduced the code to this and it would show the same
> problem:
> 
> #include <fstream>
> void f()
> {
>   std::ofstream txt_stream;
>   txt_stream.open("foo", "w");
> }
> 
> Your example is full of unrelated code that has nothing to do with the 
> problem.
> 
> > The main problem is open() function.For
> > calling open() of GCC 3.4.6,what can I do in may code and how to update my 
> > code
> > to ISO C++.Could please you give me specific example.Thank you in advance.
> 
> As I said, the second argument to ofstream::open is openmode
> e.g.
> 
>   txt_stream.open("foo", std::ios::out);
> 
> Please consult a C++ book or reference for more details.
> 
Hi,
Mr Wakely,as you said,I write a example:
using namespace std;
#include<iostream>
#include<fstream>
int main()
{
   std::ofstream txt_stream;
   int status=0;
   char txt_stream_file[100]; 
   const char *file;

  strcpy(txt_stream_file,"plots/");
  strcat(txt_stream_file,"results");
  strcat(txt_stream_file,".txt");                       
  file=txt_stream_file;                       
  txt_stream.open(file,std::ios::out);                    

if(txt_stream==NULL) 
     // if(!txt_stream.iis_open())
   cout<<"cannot open "<<file<<endl;
   exit(0);
  }
  cout<<" OK"<<endl;
  return status;
} 
It can be compiled and ran.The statement file=txt_stream_file is in order to
change char* to const char*. But open() function is not work,and out:
cannot open plots/results.txt

The open() function of gcc3.4.6 is:
 /**
       *  @brief  Opens an external file.
       *  @param  s  The name of the file.
       *  @param  mode  The open mode flags.
       *
       *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that
       *  function fails, @c failbit is set in the stream's error state.
       *
       *  Tip:  When using std::string to hold the filename, you must use
       *  .c_str() before passing it to this constructor.
      */
      void
      open(const char* __s,
           ios_base::openmode __mode = ios_base::out | ios_base::trunc)
      {
        if (!_M_filebuf.open(__s, __mode | ios_base::out))
          this->setstate(ios_base::failbit);
      }

It is void function,and how can I know the function is work.For calling open()
function succesfully,what can I do in my code.Could please you give me more
advice.
                                                                      wl wang
                                                                    
th10,August,2010


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45226

Reply via email to