Sign in to follow this  

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

Recommended Posts

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';
cout << "Unable to read file";

int _tmain(int argc, _TCHAR* argv[])


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.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this