如何使用C ++在%appdata%中创建文件 [英] How to create files in %appdata% with c++

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

问题描述

我需要在AppData中创建文件夹的帮助。
假设我想在%appdata%中创建一个名为 MyFolder的文件夹,该文件夹具有文本文件test.txt
我尝试使用< fstream> 并执行此操作;

I need help creating a Folder in AppData. Lets say I want to create a Folder in %appdata% called "MyFolder", which has the text file test.txt I tried to use <fstream> and do this;

ofstream file("%appdata%\MyFolder\test.txt");

但是它不起作用。

推荐答案

%appdata%之类的东西是特定于操作系统的,而Standard C ++没有直接的方式来处理它们。您必须编写代码来解析文件路径,并从环境中提取诸如%appdata%之类的值,或者使用非标准函数打开文件(如果存在的话)。

Things like %appdata% are OS specific, and Standard C++ has no direct means of dealing with them. You will have to write code to parse the file path, and extract values like %appdata% from the environment, or alternatively use non-standard functions to open the file, should such exist.

PS这也行不通,因为 \转引号,改为 \\。

P.S. It also wouldn't work because "\" escapes the quotes, do "\\" instead.

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

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