gpt4 book ai didi

c++ - 如何将文件名参数设置为实际文件名

转载 作者:行者123 更新时间:2023-11-28 06:18:39 25 4
gpt4 key购买 nike

我想知道如何将我的函数作为参数集接收的文件名设置为实际文件名。

我的语法是

  std::ofstream file("filename.bin",
std::ios::out | std::ios::trunc | std::ios::binary);

但这会将文件命名为“filename.bin”ofc。

如果我将文件名作为参数并将文件名保存在名为 SavedFilename 的字符串中,我将如何编写它?并以字符串命名文件而不是“filename.bin”。

谢谢。

最佳答案

你是说这样?

void foo(const char* filename) {
std::ofstream file(filename,
std::ios::out | std::ios::trunc | std::ios::binary);
// ...
}

foo("filename.bin");

关于c++ - 如何将文件名参数设置为实际文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29737620/

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