Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;在自定义目录中创建文件_C++_Createfile_Create Directory - Fatal编程技术网

C++ C++;在自定义目录中创建文件

C++ C++;在自定义目录中创建文件,c++,createfile,create-directory,C++,Createfile,Create Directory,我想在桌面/(用户指定的文件夹)中创建名为“Control.h”的文件,并向其中写入文本。我该怎么做?(对于mac)。。。。。。。。这就是我到目前为止所做的: #include <iostream> #include <fstream> #include <sys/stat.h> #include <stdlib.h> #include <stdio.h> using namespace std; int main () {

我想在桌面/(用户指定的文件夹)中创建名为“Control.h”的文件,并向其中写入文本。我该怎么做?(对于mac)。。。。。。。。这就是我到目前为止所做的:

#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);
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
char game_name[100];
cout>游戏名称;
const char*homeDir=getenv(“HOME”);
字符final[256];
sprintf(决赛,“%s/桌面/%s”、homeDir、游戏名称);
mkdir(最终版本,0775);

在那篇文章中,我问的是如何让它进入桌面。我现在问的是如何在Desktop/givenName中创建一个文件夹,并在其中创建文件名
std::ofstream out(std::string(final)+"/Control.h");
// ...
out << mytext; // write to stream
// ...
out.close();
#include <string>
// ...
{
    std::string game_name [100];
    cout << "Game Name: ";
    cin >> game_name;

    std::string homeDir = getenv ("HOME");
    std::string final=homeDir+"/Desktop/"+game_name;
    mkdir(final.c_str(),0775);