c++ - _wfreopen 适用于 c :/path/file. txt 但不适用于 c :\path\file. txt?

标签 c++ c windows winapi string

TCHAR finalpath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,finalpath);
TCHAR filename[] = TEXT("\\lista.txt");
wcscat(finalpath,filename);
wprintf(L"List will be saved to %s", finalpath);

所以这基本上证实了我最终路径确实是 c:\somepath\lista.txt

但是 _wfreopen(TEXT(finalpath),TEXT("w"),stdout);

如果我把它改成

_wfreopen(TEXT("c:/somepath/lista.txt"),TEXT("w"),stdout);

然后一切正常,为什么以及如何让它接受我的 finalpath arg?

谢谢

最佳答案

不要将 TEXT 宏与变量一起使用。我很惊讶 _wfreopen(TEXT(finalpath),TEXT("w"),stdout); 甚至可以编译。

试试 _wfreopen(finalpath,TEXT("w"),stdout);

关于c++ - _wfreopen 适用于 c :/path/file. txt 但不适用于 c :\path\file. txt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4589512/

相关文章:

用于创建服务器的 C++ 框架?

c - short/char 上的“~”运算符隐式转换为 int (C/gcc)

c++ - 是否可以为具有可变参数的宏定义 c++ 包装函数?

c++ - 访问与使用 TraceLoggingWrite 提供的事件关联的用户数据

windows - 在批处理文件中,如何判断进程是否正在运行?

c++ - C++ std::string 的各个实例是否使用相同的分配器?

c++ - 如何用GDI+绘制透明BMP

c++ - C++中实现List时在何处声明Node结构

c - 如何通过关闭 C 中的所有文件描述符来重新启动或启动进程

c - 取消引用指向不完整类型的指针