con.txt and C++

不问归期 提交于 2019-11-30 07:35:27

问题


#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;
}

output:

some text in con.txt

If i replace "con.txt" with "something.txt" then something.txt will contains the string "some text in something.txt."

I think that the file con.txt bind with a console file... What is real happened in the first case?


回答1:


CON is a reserved device name on Windows platforms. It shouldn't be used as a file name, even with an extension.

From the 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.



来源:https://stackoverflow.com/questions/4477368/con-txt-and-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!