Help us understand the problem. What is going on with this article?

備忘録:C++のStringでファイルのパス、ファイル名、拡張子の取得

More than 3 years have passed since last update.

これは何?

コマンドライン引数などでファイルのフルパスを渡されたときに、パス、ファイル名、拡張子を取得する方法の備忘録

環境はWindows

サンプル

get-path_and_file
std::string fullpath = "C:\\aaa\\bbb.txt";//fullpath.size() = 14
int path_i = fullpath.find_last_of("\\")+1;//7
int ext_i = fullpath.find_last_of(".");//10
std::string pathname = fullpath.substr(0,path_i+1);//0文字目から7文字切り出す "C:\\aaa\\"
std::string extname = fullpath.substr(ext_i,fullpath.size()-ext_i); // 10文字目から4文字切り出す ".txt"
std::string filename = fullpath.substr(path_i,ext_i-path_i);// 7文字目から3文字切り出す "bbb"
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away