1:小数点位数不能超过2
double dPrice = 5.677f;
stringstream streamPrice;
streamPrice << fixed << setprecision(2) << dPrice;
string strPrice = streamPrice.str();
2:int转string
stringstream stringStream;
stringStream << (int)uId;
string strId = stringStream.str();
3:CString转string
CString strNumber;
String sNumber = “12345”;
strNumber = T2A(sNumber);
4:判断字串是否是A,B,a,b
CString strNormal = _T("A,B,");
CString strPutIn = _T("a");
BOOL bFind = -1 != strNormal.Find(strPutIn.MakeUpper()+_T(","));
5:获取当前时间
COleDateTime oleToday = COleDateTime::GetCurrentTime();
CString strDate = oleToday.Format(_T("%Y-%m-%d")); //日期
CString strTime = oleToday.Format(_T("%H:%M:%S")); //时间
6:wstring转int,wstring转枚举
wstring strNum = "123";
int nNum = _ttoi(strNum.c_str());
EM_NUMBER emNumber = (EM_NUMBER)_ttoi(strNum.c_str());
7:递归遍历文件夹下的文件
void OnCheckFileExist(CString strPath)
{
if (strPath.IsEmpty())
{
return;
}
CFileFind fileFinder;
strPath.Append(_T("\\*.*")); //所有文件都列出
BOOL bRet = fileFinder.FindFile(strPath);
while(bRet)
{
bRet = fileFinder.FindNextFile();
if(fileFinder.IsDirectory() || fileFinder.IsDots())//递归 文件夹或 .或..
{
continue;
}
CString strFileName = fileFinder.GetFileName();//找到文件,输出文件名;
CString strFileExt = ::PathFindExtension(strFileName);//获取文件后缀(文件类型)
strFileExt.MakeLower();
CString strReNameFile = strFileName + _T(“123”);
MoveFile(strFileName ,strReNameFile);//重命名
}
}
8:弹出选择文件夹对话框
BOOL OnBrowseFile()
{
//浏览文件夹
TCHAR szBuffer[MAX_PATH] = {0};
BROWSEINFO bi;
ZeroMemory(&bi,sizeof(BROWSEINFO));
bi.hwndOwner = NULL;
bi.pszDisplayName = szBuffer;
bi.lpszTitle = _T("请选择文件夹:");
bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE ;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if (NULL == idl)
{
return FALSE;
}
SHGetPathFromIDList(idl,szBuffer);
OnVaildFolder(szBuffer);
return TRUE;
}
9:获取当前执行程序所在目录
TCHAR szPath[260] = {0};
GetModuleFileName(GetModuleHandle(NULL), szPath, MAX_PATH);
CString strPath(szPath);
strPath = strPath.Left(strPath.ReverseFind('\\'));