簡體   English   中英

如何訪問網絡文件?

[英]How to access network file?

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不支持在網絡驅動器上打開文件。 有沒有簡單的方法來解決這個問題?

試試這個:

  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驅動器實際上不是真正的物理驅動器,它只是映射到服務器上的真實物理驅動器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM