vs2015使用mkdir创建文件夹时遇到错误

0.环境

windows10
vs2015专业版

1.demo程序

#include <iostream>
#include <direct.h>
#include <io.h>

char imagePath[200] = "E:\\project\\05_22\\";
char savePath[200] = "E:/c++work/20190801/";
int main()
{
	if (0 != access(string(imagePath).c_str(), 0))
	{
		// if this folder not exist, create a new one.
		mkdir(string(imagePath).c_str());   // 返回 0 表示创建成功,-1 表示失败

	}
	if (0 != access(string(savePath).c_str(), 0))
	{
		// if this folder not exist, create a new one.
		mkdir(string(savePath).c_str());   // 返回 0 表示创建成功,-1 表示失败

	}
    
    return 0;

}

2.遇到的问题

error C4996: 'access': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _access. See online help for details.

error C4996: 'mkdir': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _mkdir. See online help for details.

3.解决

将这句” _CRT_NONSTDC_NO_DEPRECATE“,”_CRT_SECURE_NO_WARNINGS“, 添加到工程属性 -》配置属性 -》c/c++ -》预处理器 -》预处理器定义中:

4.参考

1.VS2015编译问题:The POSIX name for this item is deprecated. Instead, use the ISO C

发布了24 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_35975447/article/details/100150451