1

我正在尝试将着色器文件加载器放入我的程序中。我正在从“加载着色器”部分下的http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/loading.php复制代码。我在下面有一个更简化的非工作版本。

我已经检查过我是否包含了网站示例中包含的所有 ifstream 头文件,但出现以下错误:

error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
error C2228: left of '.good' must have class/struct/union

我的头文件看起来像这样

#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);
};

源代码如下所示:

#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?

4

1 回答 1

4

std::ifstream is in the fstream header which you have not included. Add #include <fstream> to your header or source file.

于 2013-03-30T01:41:31.077 回答