分割字符串
来源:互联网 发布:网络架构图怎么做 编辑:程序博客网 时间:2024/06/10 04:41
1。strtok分割
#include "stdafx.h"#include "stdio.h"#include <iostream>#include <fstream>#include <string>#include <map>#include <vector>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ ifstream in; in.open("..\\train.txt"); string line; vector<string> name; vector<string> num; if (in) { while (getline(in , line)) { cout << line << endl; char* str = new char[strlen(line.c_str()) + 1]; strcpy(str, line.c_str()); int i = 1; char* tmp = strtok(str, " "); while (tmp != NULL) { if (1 == i) { name.push_back(tmp); } else { num.push_back(tmp); } tmp = strtok(NULL, " "); i = 2; } delete[] str; } } else { cout << "File Error!" << endl; } in.close(); return 0;}
2.strrchr取最后一个分隔符的最后一个字符串
char copyName[1024];memset(copyName, 0, 1014);strcpy(copyName, registImgAllNames[Index[j]].c_str());char* frtpos = strrchr(copyName, '\/');char* frtpos1 = strrchr(copyName, '\\');if (frtpos < frtpos1) frtpos = frtpos1;*frtpos = '\0';frtpos = strrchr(copyName, '\/');frtpos1 = strrchr(copyName, '\\');if (frtpos < frtpos1) frtpos = frtpos1;
阅读全文
0 0
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 对自己的“平均随机数封装类”的测试
- 业务 电商 订单
- 59. Spiral Matrix II
- apply()方法和call()方法
- Gerrit使用简介
- 分割字符串
- session存入数据库
- JS之arguments 引发的一个错误
- HGDB使用-l和-L选项恢复指定的数据库对象
- Spire.PDF 教程:在C#中切换PDF层的可见性
- Meet Surprise品牌的饰品为什么值得购买
- docker-为容器添加ssh服务
- 《C++ Primer》读书笔记第十章-1-初识泛型算法 And Lambda
- java导出读取EXCEL表