c++ - 如何获取临时文件夹并设置临时文件路径?

标签 c++ path syntax-error temp

如何获取临时文件夹并设置临时文件路径?我尝试了下面的代码,但它有错误。非常感谢!

TCHAR temp_folder [255];
GetTempPath(255, temp_folder);

LPSTR temp_file = temp_folder + "temp1.txt";
//Error: IntelliSense: expression must have integral or unscoped enum type

最佳答案

这段代码添加了两个指针。

LPSTR temp_file = temp_folder + "temp1.txt";

不是 concatenating字符串,它不会为您想要的结果字符串创建任何存储。

对于 C 风格的字符串,使用 lstrcpylstrcat

TCHAR temp_file[255+9];                 // Storage for the new string
lstrcpy( temp_file, temp_folder );      // Copies temp_folder
lstrcat( temp_file, T("temp1.txt") );   // Concatenates "temp1.txt" to the end

基于 the documentation for GetTempPath ,将代码中出现的所有 255 替换为 MAX_PATH+1 也是明智的做法。

关于c++ - 如何获取临时文件夹并设置临时文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16182863/

相关文章:

cocoa - 如何使用 cocoa/obj-c 从挂载目录获取服务器主机名?

c# - 为什么我不能在 WPF 中移动路径?

python - SyntaxError 在 Python 3 中不异常(exception)

c++ - 为什么 GoF 建议在 C++ 模板方法模式实现中使用 protected (而不是私有(private))虚拟方法?

c++ - ListView 控件因列数过多而性能下降

python - 如何使用 Python 将文件导出到不同的目录?

javascript - JS 有语法错误

c++ - 使用 Pleora SDK 保存缓冲区会得到蓝色、双倍的 BMP,下方有灰色条

android - 将 jlong​​ 转换为 long 是否安全?

r - Slurm群集中的R代码无法正确读取