c++ - con.txt 和 C++

标签 c++ windows fileoutputstream

#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, and LPT9. 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/

相关文章:

python - 在 Windows 上安装 paramiko

使用 FileOutputStream 使用进度条下载 Android ION

java - removeEldestEntry 覆盖

c++ - move 构造函数 : how to handle container attribute?

c++ - 每 1 秒调用一个函数(精确地)

c++ - 为什么我的数据流在 20 或 30 行后开始重复?

android - android文件系统上的数据文件在哪里?

c++ - 构造函数语法缺少形式参数

c++ - 将原始数据写入驱动器或写入文件哪个更快?

windows - 用于设置 java 主路径/路径的批处理脚本 - 如果尚未包含,则仅添加到路径