34
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-12-31

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

環境は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"
34
31
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?