Sergey Tyulenev Sergey Tyulenev - 1 year ago 116
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?

Answer Source

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:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download