【发布时间】:2014-08-22 11:32:11
【问题描述】:
我的代码有问题,我基本上想将文件写入路径,但它似乎不起作用。代码如下:
void WriteOnFile(const char *path)
{
ofstream filetolog;
filetolog.open(path);
if (filetolog)
filetolog<< "--[[ Test ]]\n";
}
然后我像这样调用 WriteOnFile:
WriteOnFile("C:/Logs/lua/testing/filename.lua");
但它不起作用。我也试过没有if (filetolog),但它是一样的。
谁能帮帮我?
【问题讨论】:
-
检查(filetolog.is_open()) 是否为真。
-
您是否在询问会导致
ofstream::open失败的所有情况?我猜“它不起作用”意味着您的if评估为假。你说的是这个吗? -
这里有一个类似的主题和一个可行的解决方案,希望这会有所帮助! stackoverflow.com/questions/9739948/…
标签: c++ file filestream