创建目录/文件夹的安全方法 [英] Safe Way of creating directory/folder

查看:98
本文介绍了创建目录/文件夹的安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在C ++中没有创建目录/文件夹的标准方法.但是我还有另一个问题.我可以确保所有平台都支持创建目录/文件夹的方法吗? IE.

I know there is no standard method of creating directories/folders in C++. But I have another question. Can I make sure ALL platforms support a way to create directories/folders? I.E. Is it possible we face a kind of platform that doesn''t support directories/folders AT ALL?

推荐答案

mkdir [ ^ ]函数是ANSI C标准的一部分.它会存在于支持该标准的所有编译器上,包括GCC,Microsoft Visual C,Intel C,PGI C和几乎所有其他编译器.

Microsoft已将此功能标记为不推荐使用,因为它不是100%安全的,建议您使用
The mkdir[^] function is part of the ANSI C standard. It will exist on any compiler which supports this standard, including GCC, Microsoft Visual C, Intel C, PGI C, and almost all others.

Microsoft has marked this function as deprecated, as it is not 100% safe, and recomends you use _mkdir[^], which only works the Microsoft Visual C compiler.

This function does live in different headers on different compilers however.
You will need to use the method that Johny linked to include the correct headers on the correct compilers.

//Based on http://stackoverflow.com/questions/3627127/writing-cross-platform-c-code-windows-linux-and-mac-osx
#ifdef TARGET_OS_MAC
	#error I dont know where it is on MAC, probably
	#include <sys/stat.h>
#elif defined(__linux__)
	//Linux
	#include <sys/stat.h>
#elif defined(_MSC_VER)
	//Microsoft Visual C compiler
	#include <direct.h>
	#define mkdir _mkdir //Automatically use the safe function on windows
#else
	#error Unknown compiler, probably cygwin or something, probably in
	#include <sys/stat.h>
#endif




通常,您不会在移动平台上手动创建文件夹(甚至文件).您将利用它们的内部功能来存储数据库和存储数据.
在某些情况下,可以手动创建文件或文件夹,并且这些平台提供了实现此目的的方法.




Generally you would not manually create a folder (or even files) on a mobile platform. You would make use of their internal functions for databases and storing data.
There are circumstances when manually making a file or folder is acceptable, and these platforms provide methods for doing so.


按照
链接 [
follow the
Link[^] it will guide you very will


这篇关于创建目录/文件夹的安全方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆