gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:57 27 4
gpt4 key购买 nike

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

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/

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