本文整理汇总了C++中t_Str::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ t_Str::c_str方法的具体用法?C++ t_Str::c_str怎么用?C++ t_Str::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类t_Str
的用法示例。
在下文中一共展示了t_Str::c_str方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompareNoCase
// CompareNoCase
// it's amazing what features std::string lacks. This function simply
// does a lowercase compare against the two strings, returning 0 if they
// match.
int CompareNoCase(t_Str str1, t_Str str2)
{
#ifdef WIN32
return stricmp(str1.c_str(), str2.c_str());
#else
return strcasecmp(str1.c_str(), str2.c_str());
#endif
}
示例2: SetFileName
// SetFileName
// Set's the m_szFileName member variable. For use when creating the CDataFile
// object by hand (-vs- loading it from a file
void CDataFile::SetFileName(t_Str szFileName)
{
if (m_szFileName.size() != 0 && CompareNoCase(szFileName, m_szFileName) != 0)
{
m_bDirty = true;
Report(E_WARN, "[CDataFile::SetFileName] The filename has changed from <%s> to <%s>.",
m_szFileName.c_str(), szFileName.c_str());
}
m_szFileName = szFileName;
}
示例3: CreateSection
// CreateSection
// Given a section name, this function first checks to see if the given section
// allready exists in the list or not, if not, it creates the new section and
// assigns it the comment given in szComment. The function returns true if
// sucessfully created, or false otherwise.
bool CDataFile::CreateSection(t_Str szSection, t_Str szComment)
{
t_Section* pSection = GetSection(szSection);
if ( pSection )
{
Report(E_INFO, "[CDataFile::CreateSection] Section <%s> allready exists. Aborting.", szSection.c_str());
return false;
}
t_Section section;
section.szName = szSection;
section.szComment = szComment;
m_Sections.push_back(section);
m_bDirty = true;
return true;
}
示例4: Load
// Load
// Attempts to load in the text file. If successful it will populate the
// Section list with the key/value pairs found in the file. Note that comments
// are saved so that they can be rewritten to the file later.
bool CDataFile::Load(t_Str szFileName)
{
// We dont want to create a new file here. If it doesn't exist, just
// return false and report the failure.
std::fstream File(szFileName.c_str(), std::ios_base::in);
// |std::ios_base::nocreate
if ( File.is_open() )
{
bool bDone = false;
bool bAutoKey = (m_Flags & AUTOCREATE_KEYS) == AUTOCREATE_KEYS;
bool bAutoSec = (m_Flags & AUTOCREATE_SECTIONS) == AUTOCREATE_SECTIONS;
t_Str szLine;
t_Str szComment;
char buffer[MAX_BUFFER_LEN];
t_Section* pSection = GetSection("");
// These need to be set, we'll restore the original values later.
m_Flags |= AUTOCREATE_KEYS;
m_Flags |= AUTOCREATE_SECTIONS;
while ( !bDone )
{
memset(buffer, 0, MAX_BUFFER_LEN);
File.getline(buffer, MAX_BUFFER_LEN);
szLine = buffer;
Trim(szLine);
bDone = ( File.eof() || File.bad() || File.fail() );
if ( szLine.find_first_of(CommentIndicators) == 0 )
{
szComment += "\n";
szComment += szLine;
}
else
if ( szLine.find_first_of('[') == 0 ) // new section
{
szLine.erase( 0, 1 );
szLine.erase( szLine.find_last_of(']'), 1 );
CreateSection(szLine, szComment);
pSection = GetSection(szLine);
szComment = t_Str("");
}
else
if ( szLine.size() > 0 ) // we have a key, add this key/value pair
{
t_Str szKey = GetNextWord(szLine);
t_Str szValue = szLine;
if ( szKey.size() > 0 && szValue.size() > 0 )
{
SetValue(szKey, szValue, szComment, pSection->szName);
szComment = t_Str("");
}
}
}
// Restore the original flag values.
if ( !bAutoKey )
m_Flags &= ~AUTOCREATE_KEYS;
if ( !bAutoSec )
m_Flags &= ~AUTOCREATE_SECTIONS;
}
else
{
Report(E_INFO, "[CDataFile::Load] Unable to open file. Does it exist?");
return false;
}
File.close();
return true;
}