问题
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;
}
回答1:
Environment variables are case sensitive, so you need to use getenv("HOME") instead of getenv("Home").
回答2:
Use Boost Library (though there will be overhead of setting up boost on your system but its worth for doing many other stuffs in C++): boost::filesystem::create_directories()
#include <boost/filesystem.hpp>
// your code....
boost::filesystem::create_directories("/bla/a");
来源:https://stackoverflow.com/questions/21816978/how-to-create-a-folder-on-a-mac-with-c