#include <fstream>
int _tmain(int argc, _TCHAR* argv[])
{
std::ofstream F("con.txt", std::ios::out);
F << "some text in con.txt";
F.close();
return 0;
}
输出:
some text in con.txt
如果我将“con.txt
”替换为“something.txt
”,则 something.txt 将包含字符串“some text in something.txt
。”
我认为文件 con.txt 与控制台文件绑定(bind)...第一种情况真实发生了什么?
最佳答案
CON
是 Windows 平台上的保留设备名称。它不应该用作文件名,即使有扩展名也是如此。
来自documentation :
Do not use the following reserved device names for the name of a file:
CON
,PRN
,AUX
,NUL
,COM1
,COM2
,COM3
,COM4
,COM5
,COM6
,COM7
,COM8
,COM9
,LPT1
,LPT2
,LPT3
,LPT4
,LPT5
,LPT6
,LPT7
,LPT8
, andLPT9
. Also avoid these names followed immediately by an extension; for example,NUL.txt
is not recommended.
关于c++ - con.txt 和 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477368/