c++從文件路徑獲取目錄


 

#include<iostream>
#include<string>
using namespace std;

int main()
{
    //string filePath = "D:\\statistics_chengqichao\\qcc\\biaoxiandianyun.xyz";
    //int nPos = filePath.rfind('\\');
    //string prefixPath = filePath.substr(0, filePath.length() - nPos-1);
    //cout << prefixPath << endl;





    string filename = "C:\\MyDirectory\\MyFile.txt";
    

    string directory;
    const size_t last_slash_idx = filename.rfind('\\');
    if (std::string::npos != last_slash_idx)
    {
        directory = filename.substr(0, last_slash_idx);

    }
    cout << directory << endl;
    system("pause");
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM