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

Started by
1 comment, last by Nik02 9 years, 7 months ago

Hi I am trying to read a Wavefront file which was created using Blender. I put a copy of this file into the solution Explorer. When I tried to compile for the first time I got the following message:

fatal error LNK1107: invalid or corrupt file: cannot read at 0x...

It seemed like the compiler confused Blender's .obj files with some other format which also uses the .obj ending. The solution was to exclude the file from the build process in its properties.

fatal error LNK1107: invalid or corrupt file: cannot read at 0x...

Now the application does compile but there is no data displayed like I would expect it. Not sure if this is a code issue.


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

The code does not jump into the else statement. The filestream simply seems to be empty and I am directly forwarded to the cin.get(); statement. I know that there are tons of tutorials on how to parse .OBJ in C++ but I want to understand.

Advertisement

The trick was not to copy the file into the solution explorer but into the project folder.

Obj is the file extension for compiled modules (such as individual c or cpp files). The linker combines these to form the executable.

Niko Suni

This topic is closed to new replies.

Advertisement