如何访问networking文件?

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不支持打开networking驱动器上的文件。 有没有简单的方法来解决这个问题?

尝试这个:

  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(); 

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

 file is open 

所以它应该工作。

Z驱动器其实不是真正的物理驱动器,它只是映射到服务器上的真实物理驱动器。