获取文件路径

#include <stdlib.h>
#include <stdio.h>
#define _MAX_PATH 260//max length of full pathname
#define _MAX_DRIVE 3 //max length of drive component
#define _MAX_DIR 256 //max length of path component
#define _MAX_FNAME 256 //max length of file name component
#define _MAX_EXT 256 //max length of extension component
void main(){
    char full_path[_MAX_PATH];
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    char fname[_MAX_FNAME];
    char ext[_MAX_EXT];
    _makepath(full_path,"c","\\sample\\file\\","makepath","c");
    printf("_Full_path created with _makepath:%s\n\n",full_path);
    _splitpath(full_path,drive,dir,fname,ext);
    printf("Path extracted with _splitpath:\n");
    printf(" _Drive: %s\n",drive);
    printf(" _Dir: %s\n",dir);
    printf("_Filename: %s\n",fname);
    printf(" _Ext: %s\n",ext);
    //output
    _FullPath created with _makepath: c:\sample\file\makepath.c
    Path extracted with _splitpath;
    _Drive: c;
    _Dir: \sample\file\
    _Filename: makepath
    _Ext: .c

}    
string filePath = "E:\\file\\main.cpp";
string extendName;
int iBeginIndex = filePath.find_last_of(".")+1;
int iEndIndex = filePath.length();
extendName = filePath.substr(iBeginIndex,iEndIndex-iBeginIndex);
transform(extendName.begin(),extendName.end(),extendName.begin(),tolower);
cout<<extendName<<endl;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值