cannot open source file "stdafx.h" ConsoleApplication | identifier "_TCHAR" is undefine

512 Views Asked by At

im having trouble running my console app with the following format.I've looked through dozens of websites and stack overflow questions and non of them were useful.please help me figure this out:

#include "stdafx.h"
#include <iostream
using namespace std;

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


}
  1. cannot open source file "stdafx.h"

  2. identifier "_TCHAR" is undefine.

  3. it's a console project and it does'nt create those stdafx.h and stdafx.cpp files.

2

There are 2 best solutions below

8
john On

Replace _TCHAR with char, and _tmain with main.

_TCHAR is not part of the C++ language, it's an obsolete feature of the Windows API that should not be used today.

You can also remove #include "stdafx.h", it's a common convention when using the Microsoft Visual Studio compiler but it's not required. You may also need to turn off the precompiled headers option in your project.

0
Alin On

I have found the answer to this problem on my own. from the beginning the problem was the version of visual studio . so apart from the unreadable and unclear form of debugging the vs2012 does,the thing is in vs2012 this form of "int _tmain(int argc, _TCHAR* argv[])" is accepted but in vs2019 this is completely prohibited so as "#include "stdafx.h". So the key is to know what form you should use for c++ programming in different Visual Studio versions.