为什么这段代码无法读取Blender的.obj文件?

Why does this code fail to read Blender's .obj file?

本文关键字:Blender 读取 obj 文件 段代码 代码 为什么      更新时间:2023-10-16

嗨,我正试图读取使用Blender创建的Wavefront文件。我把这个文件的副本放到了解决方案资源管理器中。当我第一次尝试编译时,我得到了以下消息:

致命错误LNK1107:无效或损坏的文件:不能在0x读取…

似乎编译器混淆了Blender的。obj文件与其他格式,也使用。obj结尾。解决方案是在其属性中将该文件从构建过程中排除。

现在应用程序确实编译了,但是没有显示我期望的数据。不确定这是否是代码问题。

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
void ReadPrintFile(string _fileName)
{
    std::string line;
    std::ifstream fileStream (_fileName);   
    if (fileStream.is_open())
    {
        while (getline(fileStream,line))
        {
            cout << line << 'n';
        }
        fileStream.close();
    }
    else
    {
        cout << "Unable to read file";
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    ReadPrintFile("Drone.obj");
    std::cin.get();
    return 0;
}

代码没有跳转到else语句。文件流似乎是空的,我直接转发到cin.get();语句。我知道有很多关于如何在c++中解析。obj的教程,但我想了解。

诀窍不是将文件复制到解决方案资源管理器中,而是复制到项目文件夹中。