I am trying to get a shader file loader into my program. I am copying the code from http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/loading.php under the "Loading Shader" section. I have a more simplified non-working version below.
I've checked that I've included all the ifstream header files that the example from the website includes but I am getting the following errors:
error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
error C2228: left of '.good' must have class/struct/union
My header file looks like this
#pragma once
#include <iostream> // std::cout, std::ios
#include <sstream> // std::stringstream
#include <istream>
using namespace std;
class ShaderHandler
{
public:
ShaderHandler(void);
virtual ~ShaderHandler(void);
unsigned long getFileLength(ifstream& sfile);
};
and the source looks like this:
#include "StdAfx.h"
#include "ShaderHandler.h"
#include <Windows.h>
#include <GL/gl.h>
ShaderHandler::ShaderHandler(void)
{
}
ShaderHandler::~ShaderHandler(void)
{
}
unsigned long ShaderHandler::getFileLength(ifstream& sfile){
if( !( sfile.good() ) ){
return 0;
}
return 0;
}
The errors occur in the source file on "sfile.good()". I'm not sure about the first error, because I don't understand how I am using the undefined type. I thought it should just be using ifstream. I don't see a header file I can include for "basic_istream". According to http://en.cppreference.com/w/cpp/io/basic_istream, it should be in the header for istream, which I've included.
For the second error, I've looked at some similar questions and tried using "->". I found another common problem was that a variable might have accidentally been declared as a function, but I don't think it's that either. How can I fix these errors, and what is causing them?
std::ifstream
is in the fstream
header which you have not included. Add #include <fstream>
to your header or source file.