首页 > 解决方案 > 从保存在 .txt 文件中的数组加载 3D 立方体

问题描述

在编码方面我仍然处于中级水平,所以请原谅任何听起来不太正确的事情。

我在一个名为“cube”的 .txt 文件中创建了一个数组。我有一段我一直在处理的代码,它已部分完成,但我只是想知道,它看起来是否会按照预期的方式运行,从文件中加载信息以及我将如何加载“颜色" 和 "索引" 信息,如代码底部的注释。

bool Cube::Load(char* path)
{

    std::ifstream inFile;
    inFile.open(path);
    if (!inFile.good())
    {
        std::cerr << "Can't open text file" << path << std::endl;
        return false;
    }

    inFile >> numVertices;
    indexedVertices = new Vertex[numVertices];
    for (int i = 0; i < numVertices; i++)
    {
        //TODO use inFile to populate the indexedVertices array
        ifstream inputFile;
        inputFile.open("cube.txt");

    }

    //TO DO: Load Color information

    //TO DO: Load Indices information


    inFile.close();

    return true;
}

标签: c++multidimensional-arrayfile-io3dcube

解决方案


推荐阅读