我有一个标题定义如下

header

#pragma once

#include <map>
#include <string>
#include "gl\glew.h"
#include "glm\glm\glm.hpp"


class TextureAtlas
{
public:
    TextureAtlas(std::string fileName);
    ~TextureAtlas(void);

    // Returns the index of a sprite from its name
    //int getIndex(std::string name);

    // Returns the source rectangle for a sprite
    glm::vec4 getSourceRectangle(std::string name);

    // Returns the OpenGL texture reference
    GLuint getTexture();

    float getTextureHeight();
    float getTextureWidth();

private:
    float m_height;

    // Holds the sprite name and its index in the texture atlas
    //std::map<std::string, int> m_indices;

    // Holds the source rectangle for each sprite in the texture atlas
    std::map<std::string, glm::vec4> m_sourceRectangles;

    // The texture containing all of the sprite images
    GLuint m_texture;

    float m_width;
};

我在关联的源的以下构造函数中遇到错误

资源
#include "TextureAtlas.h"
#include "Content\Protobuf\TextureAtlasSettings.pb.h"
#include <iostream>
#include <fstream>                                      // ifstream

#define LOCAL_FILE_DIR "Content\\"

TextureAtlas::TextureAtlas(std::string fileName)
{
    TextureAtlasSettings::TextureAtlasEntries settings;

    std::string filePath(LOCAL_FILE_DIR);
    filePath.append(fileName);

    ifstream file(filePath, ios::in | ios::binary);     // ERROR!

    if (file.is_open())
    {
        if (!settings.ParseFromIstream(&file))
        {
            printf("Failed to parse TextureAtlasEntry");
        }
    }

    int numEntries = settings.entries().size();

    for (int i = 0; i < numEntries; i++)
    {
        m_sourceRectangles[settings.entries(i).name()] = glm::vec4(
            settings.entries(i).x(),
            settings.entries(i).y(),
            settings.entries(i).height(),
            settings.entries(i).width()
            );
    }
}

TextureAtlas::~TextureAtlas(void)
{
}

问题是

IntelliSense:标识符“ifstream” undefined

如果我将std::: inst放在它的前面(std::ifstream),则可以删除上面的错误,但会导致以下错误

错误C2653:“ios”:不是类或 namespace 名称

到底是怎么回事?这没有任何意义,因为我认为我已经包含了我需要的一切?!

最佳答案

在发布的代码中,您必须在类型前面加上 namespace 名称std::ifstreamstd::ios

08-06 00:34
查看更多