如何访问网络文件? [英] How to access network file?

查看:35
本文介绍了如何访问网络文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using namespace std;

ofstream myfile;
//myfile.open ("Z:\\ABC.TXT");                 // fails Z: is a network drive
//myfile.open("C:\\Temp\\ABC.TXT");            // OK
//myfile.open("Z:\\NETWORK\\02-010E.CHS");     // fails Z:\Network is a network folder

if (myfile.is_open())
    cout << "file is open" << endl;
else
    cout << "file fails to open" << endl;

myfile.close();

问题:ofstream.open 似乎不支持在网络驱动器上打开文件.有没有简单的方法可以解决这个问题?

Question: It seems that ofstream.open doesn't support to open a file on a network drive. Is there a simply way to solve this issue?

推荐答案

试试这个:

  using namespace std;

  ofstream myfile;
  myfile.open("\\\\servername\\filepath\\filename"); 
              //^^should follow this format, servername is not Z drive name

  if (myfile.is_open())
     cout << "file is open" << endl;
 else
     cout << "file fails to open" << endl;

 myfile.close();

我试图在共享服务器上打开一个文件,它输出

I tried this to open a file on a shared server, it outputs

file is open

所以它应该可以工作.

Z驱动器实际上并不是真正的物理驱动器,它只是服务器上真实物理驱动器的映射.

The Z drive is actually not real physical drive, it is just a mapping to real physical drive on the server.

这篇关于如何访问网络文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆