gpt4 book ai didi

c++ - 如何使用文件路径进行函数调用?

转载 作者:太空宇宙 更新时间:2023-11-04 03:52:46 26 4
gpt4 key购买 nike

我只想调用一个文件路径为“/home/merve/merve.txt”的函数:

void GenerateUnecryptedData(const char* pathToUnencryptedFile)
{
// File structure:
int offset=0;
ofstream myfile;
myfile.open ("pathToUnencryptedFile", ios::out | ios::app | ios::binary);

// + 20 bytes of arbitrarily chosen data (offset: 0)
myfile.seekp(offset) << CD ;
// + IV (Initialization Vector) 16 bytes (offset: 20)
offset=20;
myfile.seekp(offset) << IV;
offset=36;
// + 48 bytes of Plain Text(offset: 36)
//- PLAINTEXT = ENCRYPTEDBurada herhangi birsey yaziyor olabilir
myfile.seekp(offset) << PLAINTEXT ;

}

那么我该如何调用我的函数呢?

顺便说一句,我不太确定我的代码是否有效?我将在函数调用后尝试。

我只是一个初学者,所以请让我变得更简单!

最佳答案

只需将其作为变量传递即可。如果在它周围加上引号,它将被解释为 string 文字。另外我建议使用 std::string 而不是 char*

void GenerateUnecryptedData(std::string const pathToUnencryptedFile)
{
ofstream myFile{pathToUnencryptedFile, ios::out | ios::app | ios::binary};
}

然后你可以将其称为

GenerateUnecryptedData("/home/merve/merve.txt");

关于c++ - 如何使用文件路径进行函数调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723534/

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