Visual studio 2015.如何在编译时在代码中获取项目名称
Visual studio 2015. How get project name in code at compile time?
我可以使用宏__FILE__
获得文件的名称吗?如何获得项目名称?
一个简单的例子:
#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;
}
在项目属性的预处理器定义选项中,在已经存在的定义的末尾添加以下内容:
PROJECT_NAME = " $ (ProjectName) ";
只需在项目设置中添加编译器定义。项目名称显然是项目范围的,所以应该很容易。
您也可以使用$(ProjectName)
构建系统宏(可用的宏可以在编辑预处理器定义时看到使用<Edit..>
在下拉框中的值),并将定义放在您包含在所有项目中的属性表中。
在c++中argv[0]是可执行文件名。通常,如果您使用默认项目设置,则将可执行名称设置为项目名称。
int main(int argc, char **argv)
{
std::cout<<"Application name :"<< argv[0]<<endl;
return 0;
}
相关文章:
- 如何在我的项目中从 CMAKE 中的同一项目获取多个库
- 如何自动获取我的项目的路径并删除一些文件
- 有没有一种简单的方法可以在C++中获取特定索引之后向量中的所有项目?
- 获取位于安卓工作室中可绘制的图像的绝对路径,用于NDK项目
- 如何从安卓、高通设备获取射频/NV项目?
- 从 boost::variant 中逐个索引获取项目,就像使用 std::variant 一样
- Qt - 在QGraphicScene中拖放时如何从项目中获取文本?
- 如何获取cmake工具链文件中的项目根目录,这可能吗
- 如何使用QList<QStandardItem *>获取列中的所有项目?
- 通过查找一对项目的代码获取错误的输出,在给定的总和相等的给定列表中列表
- 当我在子菜单MFC中按项目时如何获取事件
- 如何从unordered_set获取单个项目
- 无法通过 QModelIndex 从 QTreeView 获取项目
- 从 Freeglut/Opengl 2.1 项目中获取返回值
- 如何获取外部项目定义的目标的输出路径?
- 如何从C 代码获取项目名称
- 如何使用Visual Studio Professional 2012获取C++项目的所有宏
- 在具有结构的向量中获取项目位置
- Visual studio 2015.如何在编译时在代码中获取项目名称
- 从地图中获取项目并添加到向量c++中