[vtkusers] Problem using ofstream and any vtk-class

Remo Ziegler ziegler at merl.com
Thu Jul 5 16:45:05 EDT 2001


Hi,

I want to use ofstream to write information out to a file. In the same
file I want to use vtk-classes. The compiler brings always and error,
which says, that certain classes are redefined. How can I get rid of the
problem?
Thanks for your help!

Here is a simple program producing this error during compilation:

#include "vtkVRMLExporter.h"
#include <fstream.h>
#include <iostream.h>

int main()
{
 char str[10];
 ofstream a_file("c:\\example.txt");
 a_file << "This text will now be inside of example.txt";
 a_file.close();
 ifstream b_file("c:\\example.txt");
 b_file>>str;
 cout<<str;
 b_file.close();
 return 0;
}

Error message from compiler:
c:\program files\microsoft visual studio\vc98\include\ios.h(104) : error
C2371: 'ostream' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iosfwd(257) : see declaration of 'ostream'
c:\program files\microsoft visual studio\vc98\include\ios.h(106) : error
C2371: 'ios' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iosfwd(254) : see declaration of 'ios'
c:\program files\microsoft visual studio\vc98\include\istream.h(64) :
error C2371: 'istream' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iosfwd(256) : see declaration of 'istream'
c:\program files\microsoft visual studio\vc98\include\istream.h(173) :
error C2371: 'cin' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iostream(17) : see declaration of 'cin'
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) :
error C2371: 'cout' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iostream(18) : see declaration of 'cout'
c:\program files\microsoft visual studio\vc98\include\ostream.h(140) :
error C2371: 'cerr' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iostream(19) : see declaration of 'cerr'
c:\program files\microsoft visual studio\vc98\include\fstream.h(98) :
error C2371: 'ifstream' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iosfwd(268) : see declaration of 'ifstream'
c:\program files\microsoft visual studio\vc98\include\fstream.h(118) :
error C2371: 'ofstream' : redefinition; different basic types
        c:\program files\microsoft visual
studio\vc98\include\iosfwd(269) : see declaration of 'ofstream'

Do I need some preprocessing commands?

Greets .... Remo





More information about the vtkusers mailing list