Sergey Tyulenev Sergey Tyulenev - 3 months ago 16
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

__FILE__
.
How to get the name of the project?

https://msdn.microsoft.com/library/b0084kay.aspx

Answer

A simple example on how to do it:

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

#if !defined PROJECT_NAME
#define PROJECT_NAME ""
#endif

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:

PROJECT_NAME="$(ProjectName)";