visual studio 2022 c++使用教程

介绍

参考https://github.com/1412771048/vs-demo

安装

1、官网下载vs2022企业版–选择桌面开发–安装位置–安装
2、环境–关闭产品更新

创建程序

1、空项目–不勾选将解决方案和项目放在同一目录中–填写项目名称就是程序名,解决方案名称就是工程名(一个工程就是多个项目组成的,项目可以是程序、动态库)
在这里插入图片描述
2、可以删掉三个文件夹,自己建,注意:这些文件夹不是目录,只起区分作用。
3、属性配置(见下文)

属性配置

1、选择所有配置,比较通用
2、设置语言标准
3、C/C++ -> 附加包含目录(头文件位置),如:..\Test1
4、链接器 -> 常规 -> 附加库目录,如:..\x64\$(Configuration),自动适配debug/release
5、链接器 -> 输入 -> 附加依赖项(库名),如:Test1.lib

创建动态库

1、同上,创建空项目,创建好后改成动态库
2、属性配置(见上文)
3、代码示例:

#pragma once
//动态库代码跨平台,vs/linux
#if _WIN64
	#ifdef GYL_DLL   //所有动态库都可以用同一个宏,如:GYL_DLL、GYL_API
		#define GYL_API __declspec(dllexport)
	#else
		#define GYL_API __declspec(dllimport)
	#endif
#elif __linux__ 
	#define GYL_API
#endif


//全局函数和全局变量的声明前加一个GYL_API即可
namespace space {

extern GYL_API int a;
GYL_API void func();

class GYL_API Test1 {
public:
	void f();
};

} //namespace space

生成顺序

解决方案–配置启动项目:选择哪个作为启动项目,然后依赖项逐个配置。

### Visual Studio 2022 C++ Setup and Configuration For developing applications using C++ in Visual Studio 2022, it's essential that the correct version of Visual Studio is used along with appropriate configurations. Microsoft platform targets necessitate compilation with Visual Studio 2022 17.4 (MSVC 14.34.x) or newer versions for compatibility with certain engines; thus, updating to a suitable edition of Visual Studio 2022 should be ensured while also confirming settings do not enforce an older compiler like VisualStudio2019[^1]. If encountering issues during installation such as failure messages about specific packages like “Microsoft.VisualStudio.Debugger.JustInTime”, one potential solution involves running the program/install/uninstall troubleshooter tool provided by Windows, targeting problematic components for removal before retrying the VS installer with administrative privileges after cleanup[^4]. To set up development environment properly: - **Installation**: Begin from the official download page available at [this link](https://visualstudio.microsoft.com/zh-hans/) where users can acquire Visual Studio 2022 tailored towards their needs including support for multiple languages and platforms among which C++ plays a significant role. - **Configuration Verification**: After ensuring the latest stable release has been successfully deployed on your system—preferably operating within environments similar to those described when utilizing Win10 x64—it becomes crucial to verify whether all necessary workloads related to desktop development with C++, game development with DirectX/C++ etc., have been selected during setup process. Additionally, developers aiming at cross-platform projects might consider leveraging tools outside traditional IDEs offered directly through Microsoft. For instance, integrating Visual Studio Code into workflows could provide flexibility especially beneficial under scenarios involving remote Linux servers since extensions exist specifically designed around enhancing productivity across diverse OS boundaries without sacrificing feature richness expected today[^3]. ```cpp // Example: A simple Hello World application written in C++ #include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值