0

I have a VS2013 VC++ project that I want to create a std::ifstream object like below:

#include "stdafx.h"
#include <fstream>

int _tmain(int argc, _TCHAR* argv[])
{
    std::ifstream f;
    return 0;
}

It works as expcted but if I change the header included order the compiler will issue an error:

#include <fstream>
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    std::ifstream f;
    return 0;
}
error C2065: 'ifstream' : undeclared identifier

What's in the stdafx.h file is very simple:

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

My problem is why the header included order affects the compiler to find std::ifstream? Is there any macro defined in other headers included by stdafx.h affects the result? But when I press F12 on ifstream class and jump to the definition the class is not grayed out which means they are enabled and the compiler can find them right? I have google for a while but still can't figure out why it compiles fail.

Pierre
  • 1,942
  • 3
  • 23
  • 43
JH Yang
  • 19
  • 4

0 Answers0