将文件保存到目录C
Saving A File to Directory C++
所以我在这上花费了大约30分钟的时间,没有运气。尝试了许多保存文件的方法。当我将其保存到:
中时,它有效C: USER JSMIT ONEDRIVE Documents Visual Studio 2017 Projects Projects Password Generator Password Generator
,但是当我尝试将其保存到:
中时,c: users jsmit oneedrive documents
或:
c: users jsmit documents new文件夹
这是我保存文件的代码:
void savePassword(string stringpassword, string site) {
ofstream out("C:DocumentsNew folderoutput.txt", ofstream::app); // DOESN'T WORK
out << site << ": " << stringpassword << endl; // This is where it saves the password into the text file
out.close(); // Closes file
}
如果我说:
ofstream out("Password.txt", ofstream::app); // ofstream:app stops overwrite
它有效。
edit ::::允许我保存到h: new文件夹,而不是c:drive?如何修复?
我如何制作它,以将其保存到:c: users jsmit oneDrive documents
问题是字符 使用
\
或 /
有关更多详细信息,请参见此处:
在C中,所有逃生序列由两个或多个字符组成, 首先是后斜线,;其余字符确定 逃生序列的解释。例如, n是一个 逃脱序列表示新线字符。其余的 本文侧重于C;其他编程语言可能会 具有不同的语法和语义。
像其他人所说的一样,是逃生角色。您需要在包含的含义时使用双反斜线。
您不能只写入C:除非您是管理员。
使用"%userProfile%"的" home"文件夹的快捷方式访问此文件夹,然后可以使用"%userProfile% oneDrive documents"
另外,在将任何文件写入其中之前,请确保文件夹存在。该文件夹不会自动创建,您必须自己制作。
另外,看看其他答案,''字符应该是''
- 无法通过头文件保存变量的值
- 是否有标准的文件保存和交换模式
- C++两次从文件保存对象读取多重继承
- 如何选择文件保存到的位置?
- 如何将文本文件保存到C 中的字符串结构
- 将文件保存到目录C
- 如何在不保存文件的情况下制作打印屏幕并将其发送到FTP服务器?我的工作代码将文件保存到HDD
- 从文件C++保存和读取双向量
- 使用 depend将对象文件保存在相同的生成文件目录中
- 在C++中创建文件时,创建的文件保存在何处
- 在 cab 应用程序卸载时将文件保存在文件夹中
- 读取.txt文件保存在内存中
- 如何将CSV文件保存为UTF-8
- 使用iostream将文件保存在路径
- 在Qt中将文件保存到网络
- 将链表写入 txt 文件(保存过程)
- 在 C++ 中将编辑过的内文件保存到输出文件时出现问题
- 将文件保存在不同的linux位置
- 多线程文件保存操作
- 文件保存期间的进度