当前位置:编程学习 > C/C++ >>

C++读取“aux”,“com*”文件

From Neeaos Blog

Windows 下不能够以下面这些字样来命名文件/文件夹,包括:“aux”,“c++om1”“com2”“prn”“con”和“nul”等,但是通过cmd下是可以创建此类文件夹的,使用copy命令即可实现:

\

这种文件通过gui是无法访问的,如下图:

\

但是通过IIS还是可以解析这个文件的:

\

那么是否可以用程序读取么,于是乎就测试了一下,用VS2003创建了一个项目,代码如下:

#include "stdafx.h"
#include <fstream>
#include <string>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 ifstream fin("F:\asp\com1.asp");
 string s;
    while(getline(fin,s) )
    {  
        cout << "Read from file: " << s << endl;
    }
 system("pause");
 return 0;
}
读取com1.asp并输出,如果可以读取的话,可以输出com1.asp内容,看图:

\

没有任何输出,看起来是不能直接读取了,Google一把:

html">http://blog.sina.com.cn/s/blog_4a72966b01000ana.html

找到这篇文章,说cmd下删除aux文件的,那我们通过其中说的方法看能不能读取,修改下代码:

#include "stdafx.h"
#include <fstream>
#include <string>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 ifstream fin("\\.\F:\asp\com1.asp");
 string s;
    while(getline(fin,s) )
    {  
        cout << "Read from file: " << s << endl;
    }
 system("pause");
 return 0;
}
运行下看看:

\

可以正常读取了,^_^。

 

 

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,