如何在使用C ++的Mac上创建文件夹? [英] How to create a folder on a Mac with C++?

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

问题描述

您如何让用户输入文件夹名称并在桌面上创建(对于Mac)? 到目前为止,这就是我所拥有的..(以及下面的其他代码)

How do you have the user input the folder name and have it created in the desktop (for mac)? This is what I have so far.. (and extra code underneath)

#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main ()
{
    char game_name [100];
        cout << "Game Name: ";
        cin >> game_name;

        const char* homeDir = getenv ("Home");
        char final [256];
        sprintf (final, "%s/Desktop/%s",homeDir, game_name);
        mkdir(final,0775);

其他代码... .... ... ..

other code.... .... ... ..

return 0;

}

推荐答案

环境变量区分大小写,因此您需要使用getenv("HOME")而不是getenv("Home").

Environment variables are case sensitive, so you need to use getenv("HOME") instead of getenv("Home").

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

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