Problem including fstream

I’m trying to read floats from a file and then copy the floats to the graphics card. However I get the following error messages.

/usr/lib/gcc/i386-redhat-linux/4.3.2/…/…/…/…/include/c++/4.3.2/bits/ios_base.h:410: error: declaration of ‘typedef class std::streampos std::ios_base::streampos’

/usr/lib/gcc/i386-redhat-linux/4.3.2/…/…/…/…/include/c++/4.3.2/bits/postypes.h:207: error: changes meaning of ‘streampos’ from ‘typedef class std::fpos<__mbstate_t> std::streampos’

/usr/lib/gcc/i386-redhat-linux/4.3.2/…/…/…/…/include/c++/4.3.2/bits/ios_base.h:411: error: declaration of ‘typedef std::streamoff std::ios_base::streamoff’

/usr/lib/gcc/i386-redhat-linux/4.3.2/…/…/…/…/include/c++/4.3.2/bits/postypes.h:71: error: changes meaning of ‘streamoff’ from ‘typedef int64_t std::streamoff’

/usr/lib/gcc/i386-redhat-linux/4.3.2/…/…/…/…/include/c++/4.3.2/streambuf:147: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)

#include <iostream>

	#include <fstream>

std::ifstream file("../data/reference_volume_127x127x127.bin");

	float current_value;	

	if (file.good())

	{

		file >> current_value;

			   ...

	}

	else

	{

		printf("Could not find file! \n");

	}

	file.close();

If I make a separate file and compile the file reading code with g++ it works, gcc works if I add -lstdc++. Since nvcc uses gcc (?) I tried adding -lstdc++ in the common.mk file but it did not help.

# Libs

LIB	   := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) 

LIB += -lstdc++

ifeq ($(USEDRVAPI),1)

   LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB} 

else

   LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}

endif

Solution is probably to not use gcc 4.3; install gcc 4.1 or 4.2 and use that instead.

Try sticking this bunch of arcane stuff at the beginning of your file:

#include <cwchar>

namespace std { 

	typedef int64_t streamoff;

	template <typename foo> class fpos; 

	typedef fpos<mbstate_t> streampos;

}

using std::streamoff;

using std::streampos;

Of course, we shouldn’t need to do that. Apparently, something in nvcc is stripping away the std:: from a few symbols, and confusing things.