常用字符串封装方法
1 GetAppExePath
得到执行路径
2 str_2转并且得到字符串
3 int_2转得到整形
4 isNumber是否时数字
5 format字符串格式化
6 split字符串分割
7 string_to_upper 8 string_to_lower字符串变大小写
9 ifnote是否时注释
10 trim去空格
show me the code#ifndef _UTIL_TOOL_H_
#define _UTIL_TOOL_H_
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#ifndef _WIN32
#include
#endif
using namespace std;
#define MAX_PATH 260
static void GetAppExePath(string &name)
{
char path_buffer[MAX_PATH] = { 0 };
_getcwd(path_buffer, MAX_PATH);
strcat(path_buffer, "/");
strcat(path_buffer, name.c_str());
name = path_buffer;
}
template
std::string str_2(const T& t)
{
std::ostringstream oss;
oss x))
return 0;
return x;
}
static bool isNumber(const std::string& str)
{
for (std::size_t i = 0; i 0)
{
ret.push_back(s.substr(last, index - last));
}
}
static inline void CharUpper(char& c)
{
if (c = 97)
c = c - 32;
}
static inline void CharLower(char& c)
{
if (c = 65)
c = c + 32;
}
static inline void string_to_upper(string& strsource)
{
void(*FUNC)(char& c);
FUNC = CharUpper;
for_each(strsource.begin(), strsource.end(), FUNC);
}
static inline void string_to_lower(string& strsource)
{
void(*FUNC)(char& c);
FUNC = CharLower;
for_each(strsource.begin(), strsource.end(), FUNC);
}
static bool load_conf_file(const char *filename)
{
//std::ifstream myfile("./config.txt");
if (filename == NULL)
filename = "config.txt";
std::ifstream myfile(filename);
std::string temp;// , node, nodename;
if (!myfile.is_open())
{
std::cout
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?