gpt4 book ai didi

c++ - 将文件保存到目录 C++

转载 作者:行者123 更新时间:2023-11-30 01:40:57 25 4
gpt4 key购买 nike

所以我花了大约 30 分钟,但没有运气。尝试了多种保存文件的方法。当我将它保存到:
C:\Users\jsmit\OneDrive\Documents\Visual Studio 2017\Projects\密码生成器\密码生成器

但当我尝试将其保存到:

C:\Users\jsmit\OneDrive\Documents

或者:

C:\Users\jsmit\Documents\新建文件夹

这是我保存文件的代码:

void savePassword(string stringpassword, string site) {

ofstream out("C:\Documents\New folder\output.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: 驱动器?如何修复?

我如何制作它以便将其保存到:C:\Users\jsmit\OneDrive\Documents

最佳答案

问题是字符 \ 使用 \\/

参见 here了解更多详情:

In C, all escape sequences consist of two or more characters, the first of which is the backslash, \; the remaining characters determine the interpretation of the escape sequence. For example, \n is an escape sequence that denotes a newline character. The remainder of this article focuses on C; other programming languages are likely to have different syntax and semantics.

关于c++ - 将文件保存到目录 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42369371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com