- 检测路径是否可用
<io.h>
_access(strPath.c_str(),0);
//把路径中的斜线
replace("/","\\");
- 字符数组复制
strncpy(char* Des, const char* Source, size_t count);
sprintf_s(char(&Buffer)[size], const char* Format, const char* Source);
- 整型转字符串/长整型转字符串
std::string long_long_to_string(const long long& value)
{
char tmp[64]={0};
#if defined (_WIN32) || defined(_WIN64)
_snprintf(tmp, sizeof(tmp)-1, "%lld", value);
#else
snprintf(tmp, sizeof(tmp), "%lld", value);
#endif
std::string temp_str=tmp;
return temp_str;
}
4.获取系统时间
time_t getCurrentTime()
{
SYSTEMTIME st;
GetLocalTime(&st);
struct tm gm={st.wSwcond,st.wMinute,\
st.wHour,st.Day,st.wMonth-1,\
st.wYear-1900,st.wDayOfWeek, 0,0};
time_t tTrans=mkTime(&gm);
return tTrans*1000+st.wMilliseconds;
}
5.检查IP是否正常
int IsValidIP(const char* szIpAddr)
{
unsigned b1 b2 b3 b4;
unsigned char c;
int rc=sscanf(szIpAddr,"%3u.%3u.%3u.%3u%c",&b1,&b2,&b3,&b4,&c);
if(rc!=4)
return false;
if(!isspace(c))
return false;
if((b1|b2|b3|b4)>255)
return false;
return true;
}