常用字符串封装方法
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
关注
打赏