首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c++ 字符串 截取有关问题

2013-07-29 
c++字符串 截取问题string pathC:\\aaa\\bb\\cc.txt怎样操作 得到 文件位置路径MainpathC:\\aaa\\b

c++ 字符串 截取问题
string path="C:\\aaa\\bb\\cc.txt";
怎样操作 得到 文件位置路径  Mainpath=""C:\\aaa\\bb\";

[解决办法]
如果能保证path中一定是完整的路径名的话:


string::size_type pos = path.find_last_of('\\');
if( pos != string::npos )
{
   mainpath.assign( path, 0, pos + 1 );
}


最好还是用boost::filesystem。

热点排行