c++常用知识

1.获取当前工作路径

头文件:

#include 
#include 
TCHAR sFullPath[MAX_PATH + 1] = { 0 };
    TCHAR buffer[MAX_PATH ] = {0};
    TCHAR sDrive[_MAX_DRIVE];
    TCHAR sDir[_MAX_DIR ];
    TCHAR sfName[_MAX_FNAME ];
    TCHAR sExrt[_MAX_EXT];
    GetModuleFileName(nullptr, buffer, MAX_PATH);

    //分割路径
    _wsplitpath_s(buffer, sDrive, _MAX_DRIVE, sDir,
                  _MAX_DIR, sfName, _MAX_FNAME, sExrt, _MAX_EXT);

    //合并路径"F:\workspace\code\bin\"   
    
    _stprintf(sFullPath, _T("%s%s"), sDrive, sDir);

2. 将tchar 转化为 string 类型

//将 tchar 转换为 string 类型
     int iLen = WideCharToMultiByte(CP_ACP, 0,sFullPath, -1, NULL, 0, NULL, NULL);
    char* charTemp =new char[iLen*sizeof(char)];
    WideCharToMultiByte(CP_ACP, 0, sFullPath, -1, charTemp, iLen, NULL, NULL);
    std::string strDir(charTemp);

3. string.replace不支持将所有的字符都替换掉

只能一个字符一个字符的替换掉

4.  atof 与 _ttof

你可能感兴趣的:(C/C++,c++,开发语言)