简体   繁体   English

C ++在Program文件中的make文件夹

[英]C++ make folder inside Program files

I am trying to create a directory inside program files, but my code failed. 我试图在程序文件中创建目录,但是我的代码失败。 I can make folder directly on the root, so this is very strange I think. 我可以直接在根目录下创建文件夹,所以我认为这很奇怪。

#include "stdafx.h"
#include <iostream>
using namespace std; 

#include <direct.h> // _mkdir

int _tmain(int argc, _TCHAR* argv[])
{
    // Make directory
    if(_mkdir("C:\\Program Files\\MyProgram") == 0 ){
        cout << "Folder created" << endl; 
    }
    else{
         cout << "Folder creation failed" << endl; 
    }


    // Pause program
    system("PAUSE"); 
    return 0;
}

Edit: Thank you. 编辑:谢谢。 I understand that c:\\Program files\\MyProgram is only for install files, but where should I put save files? 我知道c:\\ Program files \\ MyProgram仅用于安装文件,但是我应该在哪里保存文件? Example save files for a C++ game. 示例为C ++游戏保存文件。 Should they be stored in "C:\\Users\\Username\\Documents\\MyProgram"? 是否应将它们存储在“ C:\\ Users \\ Username \\ Documents \\ MyProgram”中?

The proper folder name to write depends on version and localization. 要写入的正确文件夹名称取决于版本和本地化。

A simple way to get that name is to search for the APPDATA environment variable. 获得该名称的一种简单方法是搜索APPDATA环境变量。

See here to get an environment variable, and here about the recognized environment variables and meanings. 这里得到一个环境变量,并在这里对公认的环境变量的含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM