您当前的位置: 首页 >  c++

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

c++ 常用字符串封装函数

qianbo_insist 发布时间:2021-07-11 15:13:39 ,浏览量:0

常用字符串封装方法 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             
关注
打赏
1663161521
查看更多评论
0.0396s