如何使用C ++编程创建文件夹? [英] How to create a folder using C++ programming?

查看:143
本文介绍了如何使用C ++编程创建文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c ++编程创建文件夹?

How to create a folder using c++ programming?

推荐答案

它对我有效,而无需使用API​​和system()函数!
It works for me without using API and system() function!
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dir.h>
#define DIRNAME "c:\\testdir"
int main(void)
{
   int stat;
   stat = mkdir(DIRNAME);
   if (!stat)
      printf("Directory created\n");
   else
   {
      printf("Unable to create directory\n");
      exit(1);
   }
   getch();
   system("dir/p");
   getch();
   stat = rmdir(DIRNAME);
    if (!stat)
      printf("\nDirectory deleted\n");
   else
   {
      perror("\nUnable to delete directory\n");
      exit(1);
   }
   return 0;
}


CreateDirectory 是创建目录的Windows API调用.
Directory::CreateDirectory等同于.NET(假设您使用的是C ++/CLI).

我不相信标准C ++具有目录的概念,因为它依赖于操作系统.
CreateDirectory is the Windows API call that creates a directory.

Directory::CreateDirectory would be the .NET equivalent (assuming you are using C++/CLI).

I don''t believe Standard C++ has the concept of directories since that is OS dependent.


C ++不使用API​​创建目录.如果您使用的是Windows/Managed C ++,请遵循Nishant的答案.对于标准C ++,您可以使用C运行时 _tmkdir [ ^ ]

C++ does not API to create directories. If you are using Windows/Managed C++, follow Nishant answer. For standard C++ you can use the C run-time _tmkdir[^]

_tmkdir("\\testtmp")


这篇关于如何使用C ++编程创建文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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