本文整理汇总了C++中AnsiStr::ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ AnsiStr::ptr方法的具体用法?C++ AnsiStr::ptr怎么用?C++ AnsiStr::ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnsiStr
的用法示例。
在下文中一共展示了AnsiStr::ptr方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
bool IniFile::readIntArrayU32(const AnsiStr& section, const AnsiStr& variable, int ctExpected, std::vector<U32>& arrayInt)
{
AnsiStr strVal;
if(readValue(section, variable, strVal))
{
int pos;
int iComp = 0;
AnsiStr strTemp;
if(strVal.firstChar() == '(')
strVal = strVal.substr(1);
else
return false;
while(strVal.lfind(',', pos))
{
strTemp = strVal.substr(0, pos);
strVal = strVal.substr(pos + 1);
strVal.removeStartEndSpaces();
arrayInt.push_back(atoi(strTemp.ptr()));
iComp++;
}
if(strVal.length() >= 1)
{
if(strVal.lastChar() == ')')
{
strTemp = strVal.substr(0, strVal.length() - 1);
strTemp.removeStartEndSpaces();
if(strTemp.length() > 0)
arrayInt.push_back(atoi(strTemp.ptr()));
}
}
}
return ((int)arrayInt.size() == ctExpected);
}
示例2: readInt
//====================================================================================
int IniFile::readInt(const AnsiStr& section, const AnsiStr& variable, int def)
{
AnsiStr strVal;
if(readValue(section, variable, strVal))
//def = atoi(strVal.c_str());
def = atoi(strVal.ptr());
return def;
}
示例3: readBool
//====================================================================================
bool IniFile::readBool(const AnsiStr& section, const AnsiStr& variable, bool def)
{
AnsiStr strVal;
if(readValue(section, variable, strVal))
//def = (atoi(strVal.c_str()) == 1)?true:false;
def = (atoi(strVal.ptr()) == 1)?true:false;
return def;
}
示例4: readDouble
//====================================================================================
double IniFile::readDouble(const AnsiStr& section, const AnsiStr& variable, double def)
{
AnsiStr strVal;
if(readValue(section, variable, strVal))
//def = atof(strVal.c_str());
def = atof(strVal.ptr());
return def;
}
示例5: readFloat
//====================================================================================
float IniFile::readFloat(const AnsiStr& section, const AnsiStr& variable, float def)
{
AnsiStr strVal;
if(readValue(section, variable, strVal))
//def = static_cast<float>(atof(strVal.c_str()));
def = static_cast<float>(atof(strVal.ptr()));
return def;
}
示例6: WriteTextFile
bool WriteTextFile(const AnsiStr& strFN, const AnsiStr& strContent )
{
ofstream ofs(strFN.ptr(), ios::out | ios::trunc);
if(!ofs.is_open())
return false;
ofs << strContent << '\0' << '\n';
ofs.close();
return true;
}
示例7: FileExists
//==================================================================
bool FileExists(const AnsiStr& strFilePath)
{
ifstream ifs(strFilePath.ptr(), ios::in | ios::binary );
if(ifs.is_open())
{
ifs.close();
return true;
}
else
{
return false;
}
}
示例8: GetFileSize
long GetFileSize(const AnsiStr& strFilePath)
{
ifstream ifs(strFilePath.ptr(), ios::in | ios::binary );
if(!ifs.is_open())
return -1;
long begin, end;
begin = ifs.tellg();
ifs.seekg(0, ios::end);
end = ifs.tellg();
ifs.close();
return end - begin;
}
示例9: GetExePathPlatform
//==================================================================
void GetExePathPlatform(char *exePath, int szBuffer)
{
#ifdef PS_OS_MAC
uint32_t szExePath = szBuffer;
if(_NSGetExecutablePath(exePath, &szExePath) == 0)
exePath[szBuffer] = 0;
else {
exePath[0] = 0;
printf("Not enough memory to get exepath. Needs %d\n", szBuffer);
}
/*
AnsiStr strInput(exePath, )
int index = result.lastIndexOf(QString(".app"));
if(index < 0)
index = result.length();
else
result = result.left(index);
index = result.lastIndexOf(QString("/"));
if(index < 0)
{
index = result.lastIndexOf(QString("\\"));
if(index < 0)
index = result.length();
}
result = result.left(index + 1);
*/
#elif defined(PS_OS_WINDOWS)
WCHAR wszExeName[MAX_PATH + 1];
wszExeName[MAX_PATH] = 0;
GetModuleFileNameW(NULL, wszExeName, sizeof(wszExeName) - 1);
WideCharToMultiByte(CP_ACP, 0, wszExeName, -1, (LPSTR)exePath, szBuffer, NULL, NULL);
#elif defined(PS_OS_LINUX)
//getcwd only retrieves the current working directory
//getcwd(exePath, (int)szBuffer);
pid_t pid = getpid();
AnsiStr strProcessPath = printToAStr("/proc/%d/exe", pid);
int nCharsWritten = readlink(strProcessPath.ptr(), exePath, szBuffer);
if(nCharsWritten != -1)
{
exePath[nCharsWritten] = 0;
}
#endif
}
示例10: ReadTextFile
bool ReadTextFile(const AnsiStr& strFN, AnsiStr& strContent )
{
ifstream ifs(strFN.ptr(), ios::in);
if(!ifs.is_open())
return false;
AnsiStr strLine;
char buffer[2048];
while( !ifs.eof())
{
ifs.getline(buffer, 2048);
//ifs >> strLine;
strLine.copyFromT(buffer);
strLine.trim();
strContent.appendFrom(strLine);
}
ifs.close();
return true;
}
示例11: ListFilesInDir
//==================================================================
int ListFilesInDir(std::vector<AnsiStr>& lstFiles, const char* pDir, const char* pExtensions, bool storeWithPath)
{
AnsiStr strDir;
AnsiStr strResolvedDir;
lstFiles.resize(0);
if(pDir == NULL)
strResolvedDir = ps::dir::ExtractFilePath(ps::dir::GetExePath());
else
strResolvedDir = AnsiStr(pDir);
if(pExtensions != NULL)
strDir = printToAStr("%s/*.%s", strResolvedDir.ptr(), pExtensions);
else
strDir = printToAStr("%s/*.*", strResolvedDir.ptr());
#ifdef PS_OS_WINDOWS
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWideStr wstrDir = toWideString(strDir);
hFind = FindFirstFile(wstrDir.ptr(), &ffd);
if(hFind == INVALID_HANDLE_VALUE)
return 0;
AnsiStr temp;
do
{
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
if (storeWithPath)
{
temp = strResolvedDir + "\\";
temp += AnsiStr(ffd.cFileName);
lstFiles.push_back(temp);
}
else
{
temp = AnsiStr(ffd.cFileName);
lstFiles.push_back(temp);
}
}
}while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#else
DIR* dirFile = opendir( strResolvedDir.cptr() );
if ( dirFile )
{
struct dirent* hFile;
string strExt = "." + string(pExtensions);
while (( hFile = readdir( dirFile )) != NULL )
{
if ( !strcmp( hFile->d_name, "." )) continue;
if ( !strcmp( hFile->d_name, ".." )) continue;
// in linux hidden files all start with '.'
if (hFile->d_name[0] == '.' ) continue;
// dirFile.name is the name of the file. Do whatever string comparison
// you want here. Something like:
if ( strstr( hFile->d_name, strExt.c_str())) {
if(storeWithPath)
lstFiles.push_back(strResolvedDir + "//" + AnsiStr(hFile->d_name));
else
lstFiles.push_back(AnsiStr(hFile->d_name));
printf("Found file %s", hFile->d_name);
}
}
closedir( dirFile );
}
#endif
return (int)lstFiles.size();
}