📄 utility.cpp
字号:
//PK 2006/07/24 - 10/18
#include "utility.h"
wstring
c2w(const string & txt)
{ //PK 2006/07/24
wchar_t * buf = new wchar_t[txt.length() + 1];
mbstowcs(buf, txt.c_str(), txt.length());
buf[txt.length()] = L'\0';
wstring ret = buf;
delete [] buf;
return ret;
}
string
w2c(const wstring & txt)
{ //PK 2006/07/24
char * buf = new char[txt.length() + 1];
wcstombs(buf, txt.c_str(), txt.length());
buf[txt.length()] = '\0';
string ret = buf;
delete [] buf;
return ret;
}
string
ulong2c(const unsigned long l)
{ //PK 2006/09/22
char buf [20];
_ltoa(l, buf, 10);
return buf;
}
wstring
ulong2w(const unsigned long l)
{ //PK 2006/08/02
wchar_t buf [20];
_ltow(l, buf, 10);
return buf;
}
wstring
time2w(const unsigned int seconds)
{ //PK 2006/08/02
wstring txt;
wchar_t buf[10];
unsigned int hours = seconds / 3600;
if (hours < 10) txt += L"0";
_itow(hours, buf, 10);
txt = txt + buf + L":";
unsigned int minutes = (seconds % 3600) / 60;
if (minutes < 10) txt += L"0";
_itow(minutes, buf, 10);
txt = txt + buf + L":";
unsigned int remains = seconds % 60;
if (remains < 10) txt += L"0";
_itow(remains, buf, 10);
txt += buf;
return txt;
}
CRandom::CRandom()
{ //PK 2006/08/14
srand(static_cast<unsigned int>(time(NULL)));
}
int
CRandom::get_number(int low, int up)
{ //PK 2006/08/10 - 14
int range = up - low + 1;
return (rand() % range) + low;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -