Sergey Tyulenev Sergey Tyulenev - 4 months ago 24
C++ Question

Visual studio 2015. How get project name in code at compile time?

Can I get the name of the file using a macro

How to get the name of the project?


A simple example on how to do it:

#include "stdafx.h"
#include <iostream>
#include <string>

#if !defined PROJECT_NAME
#define PROJECT_NAME ""

int _tmain(int argc, _TCHAR* argv[])
    std::string str(PROJECT_NAME);
    std::cout << str;
    return 0;

In the Preprocessor Definitions option of the project properties add the following to the end of the already present definitions: