find_first_of()和 find_last_of() 【获取路径、文件名】
来源:互联网 发布:佛山淘宝代运营 编辑:程序博客网 时间:2024/04/29 01:57
string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加。我们将介绍一些主要函数。
1.函数find_first_of()和 find_last_of() 执行简单的模式匹配,如在字符串中查找单个字符c。函数find_first_of() 查找在字符串中第1个出现的字符c,而函数find_last_of()查找最后一个出现的c。匹配的位置是返回值。如果没有匹配发生,则函数返回-1.
// WJ.cpp :
//
#i nclude "stdafx.h"
#i nclude<iostream>
#i nclude<string>
using namespace std;
int main()
{
string pathname, path, filename,executableFile;
// ‘\’和 '.'的位置
int backslashIndex, dotIndex;
cout << "Enter the path name: ";
cin >> pathname;
// 识别最后一个'\'的位置。注意:由于
// 转义码如'\n'以\起始,
// c++ 使用'\\'表示 \
backslashIndex = pathname.find_last_of('\\');
//路径名是最后一个'\'之前的字符
path = pathname.substr(0,backslashIndex);
cout << "path:
// 路径名尾部是文件名
filename = pathname.substr(backslashIndex+1,-1);
cout << "Filename: " << filename << endl;
// 查看文件名是否有'.cpp'扩展名。
// 首先找到最后一个'.'的位置。 如果
// 没有'.',则dotIndex为-1
dotIndex = filename.find_last_of('.');
//测试是否有'.',其余的字符是否为"cpp"
if (dotIndex != -1 && filename.substr(dotIndex+1) == "cpp")
{
}
return 0;
}
- find_first_of()和 find_last_of() 【获取路径、文件名】
- find_first_of()和 find_last_of() 【获取路径、文件名】
- find_first_of()和 find_last_of() 【获取路径、文件名】
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- 函数find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- find_first_of()和 find_last_of()
- CString中find_first_of和find_last_of()函数
- 20170604_string中的函数find_first_of()和 find_last_of()
- find_first_of();find_last_of();find();
- 字符串处理函数find_first_of和find_last_of的使用
- 在vim下按F4自动添加作者信息,文件创作时间等
- This support library should not use a different version (24) than the compileSdkVersion (23)...
- 全局设置网页代理
- 美拍视频收集最新绿色免费版
- 关于xtrafinder 在mac下不能使用以及SIP关闭无效的问题
- find_first_of()和 find_last_of() 【获取路径、文件名】
- ssm框架搭建+easyui增删改查实现
- 如何发现优秀的开源项目?
- JAVA学习笔记--- 静态变量、成员变量、局部变量及类的初始化顺序
- 分别使用OC和Swift语法创建单例
- MySQL大表优化方案
- Android 高仿知乎日报(1)
- C#入门4.2——数学运算符
- Binder机制简单分析