本文整理汇总了C++中_tstring::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ _tstring::c_str方法的具体用法?C++ _tstring::c_str怎么用?C++ _tstring::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_tstring
的用法示例。
在下文中一共展示了_tstring::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::string StringT2A(const _tstring & tstr)
{
std::string strRes;
#ifdef UNICODE
size_t sz;
wcstombs_s(&sz, NULL, 0, tstr.c_str(), 0);
char * pstr = new char[sz + 1];
wcstombs_s(&sz, pstr, sz + 1, tstr.c_str(), sz);
strRes = pstr;
delete[] pstr;
#else
strRes = tstr;
#endif
return strRes;
}
示例2: CompileShaderFromString
BOOL XShader::CompileShaderFromString( GLuint *shader
, GLenum type
, const GLchar *cShader
, const char *cszTag )
{
GLint status;
*shader = glCreateShader( type );
glShaderSource( *shader, 1, &cShader, nullptr );
glCompileShader( *shader );
GLint logLength;
glGetShaderiv( *shader, GL_INFO_LOG_LENGTH, &logLength );
if( logLength > 0 ) {
GLchar *log = (GLchar *)malloc( logLength );
glGetShaderInfoLog( *shader, logLength, &logLength, log );
if( logLength > 0 ) {
const _tstring strTag = C2SZ(cszTag);
const _tstring strLog = C2SZ(log);
XTRACE( "Shader compile log:\n %s\n [%s]\n", strTag.c_str(), strLog.c_str() );
}
free( log );
}
glGetShaderiv( *shader, GL_COMPILE_STATUS, &status );
if( status == 0 ) {
glDeleteShader( *shader );
return NO;
}
return YES;
}
示例3: _tstring
//---------------------------------------------------------------------
// PathRenameExtensionのラッパー
//---------------------------------------------------------------------
_tstring kjm::util::path_rename_extension(const _tstring& pszPath, const _tstring& pszExt) {
TCHAR buffer[MAX_PATH];
if (PathRenameExtension(lstrcpy(buffer, pszPath.c_str()), pszExt.c_str()) == FALSE) {
return _tstring(); // 関数失敗の時は、空文字列を返す
}
return buffer;
}
示例4: UpdateSlidingResource
void XSceneTrader::UpdateSlidingResource(const char *key, XGAME::xtResource resource)
{
if (m_slider[resource]) {
const int maxRes = ACCOUNT->GetResource(resource);
const int numCurr = int(maxRes * m_slider[resource]->GetCurr());
const _tstring str1 = XE::NtS(numCurr);
const _tstring str2 = XE::NtS(maxRes);
xSET_TEXT(this, key, XFORMAT("%s / %s", str1.c_str(), str2.c_str()));
m_resourceGold[resource] = int(numCurr * XGC->m_resourceRate[resource]);
UpdateTotalGold();
}
}
示例5: buffer
//---------------------------------------------------------------------
// GetPrivateProfileString関数のラッパー
//---------------------------------------------------------------------
_tstring kjm::util::get_private_profile_string(const _tstring& lpSectionName, const _tstring& lpKeyName, const _tstring& lpDefault, const _tstring& lpFileName) {
std::vector<TCHAR> buffer(512);
while (1) {
int nRet = GetPrivateProfileString(lpSectionName.c_str(), lpKeyName.c_str(), lpDefault.c_str(), &buffer[0], buffer.size(), lpFileName.c_str());
if (buffer.size() - 1 > nRet) {
// バッファのサイズ - 1が、戻り値よりも大きいときは、
// すべての文字を読み込んだことが確実なので、ループを抜ける。
break;
}
buffer.resize(buffer.size() * 2);
}
return &buffer[0];
}
示例6: UpdateHardMark
XWndImage* XWndSpot::UpdateHardMark( const char* cIdentifier, bool bShow )
{
// 애초에 출력할필요 없는 스팟은 컨트롤을 만들지 않는다.
if( !bShow ) {
auto pExist = Find( cIdentifier );
if( pExist )
pExist->SetbShow( bShow );
return SafeCast2<XWndImage*>( pExist );
}
// 스팟 난이도 아이콘
int power = m_pBaseSpot->GetPower();
if( power == 0 ) {
m_pBaseSpot->UpdatePower();
power = m_pBaseSpot->GetPower();
}
if( XASSERT(power) ) {
int lvHard = XGAME::GetHardLevel( power, ACCOUNT->GetPowerExcludeEmpty() );
auto pImg = XWndImage::sUpdateCtrl( this, XE::VEC2(0), nullptr, true, cIdentifier );
if( pImg ) {
pImg->SetPriority( -100 );
pImg->SetbShow( true );
const auto bb = GetBoundBoxByVisibleLocal();
const auto vSize = pImg->GetSizeLocal();
pImg->SetX( -( vSize.w * 0.5f ) );
pImg->SetY( bb.vLT.y - (vSize.h * 0.8f) );
const _tstring strImg = XE::Format( _T( "world_hard%d.png" ), lvHard + 2 );
const _tstring strPath = XE::MakePath( DIR_UI, strImg );
pImg->SetSurfaceRes( strPath.c_str(), XE::xPF_ARGB1555, true );
}
return pImg;
}
return nullptr;
}
示例7: OnDidFinishLoad
bool XPropBgObj::OnDidFinishLoad()
{
LPCTSTR szTag = _T("root");
XEXmlNode nodeRoot = FindNode( "root" );
if( nodeRoot.IsEmpty() ) {
XALERT("%s: not found root node", GetstrFilename().c_str() );
return false;
}
XEXmlNode nodeChild = nodeRoot.GetFirst();
if( nodeChild.IsEmpty() ) {
return false;
}
while( !nodeChild.IsEmpty() ) {
const std::string strNodeName = nodeChild.GetcstrName();
const _tstring strtNodeName = C2SZ( strNodeName );
auto type = (XGAME::xtBgObj)CONSTANT->GetValue( strtNodeName );
if( type > XGAME::xBOT_NONE && type < XGAME::xBOT_MAX ) {
LoadObj( nodeChild, type, strtNodeName.c_str() );
} else {
PROP_LOG( "%s: 알수없는 노드", nodeChild.GetstrName().c_str() );
}
//
nodeChild = nodeChild.GetNext();
}
XTRACE( "propBgObj loaded....num=%d", m_listBgObjs.size() );
if( m_bError ) {
XALERT("%s: 로딩중 에러 발견.", GetstrFilename().c_str() );
}
return true;
}
示例8: StringToHex
void StringToHex(const _tstring &ts, unsigned char *pBuffer, size_t nBytes)
{
const std::string s = StringT2A(const_cast<TCHAR *>(ts.c_str()));
for (size_t i = 0; i < nBytes; i++)
{
const size_t stringOffset = i * 2;
unsigned char val = 0;
const unsigned char b = s[stringOffset];
if (isdigit(b))
{
val = (unsigned char)((b - '0') * 16);
}
else
{
val = (unsigned char)(((toupper(b) - 'A') + 10) * 16);
}
const unsigned char b1 = s[stringOffset + 1];
if (isdigit(b1))
{
val += b1 - '0';
}
else
{
val += (unsigned char)((toupper(b1) - 'A') + 10);
}
pBuffer[i] = val;
}
}
示例9: SplitString
void SplitString(const _tstring & src, const TCHAR delim, std::vector<_tstring> & strArr)
{
strArr.clear();
int i = 0, j;
int k = static_cast<int>(src.length());
const TCHAR * pSrc = src.c_str();
while (i < k)
{
while (*pSrc == delim && i < k)
{
pSrc++;
i++;
}
j = i;
while (*pSrc != delim && i < k)
{
pSrc++;
i++;
}
if (j < i)
{
strArr.push_back(src.substr(j, i - j));
}
}
}
示例10: dump
/*
In python:
>>> '海阔天空'.encode('utf-16')
b'\xff\xfewm\x14\x96)Yzz'
>>> '海阔天空'.encode('utf-16-le')
b'wm\x14\x96)Yzz'
>>> '海阔天空'.encode('utf-16-be')
b'mw\x96\x14Y)zz'
>>> chr(0x7a)
'z'
>>> chr(0x59)
'Y'
Output of this program: (Unicode mode)
GB2312: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-8 without BOM: 娴烽様澶╃┖
34 5a fd 70 d8 69 b6 6f 43 25 16 25
UTF-8 with BOM: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-16 BE: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-16 LE: 海阔天空
77 6d 14 96 29 59 7a 7a
So, windows uses UTF-16-LE to represent a string in UNICODE mode.
In non-unicode mode, cp936 is used.
*/
void dump(const _tstring &str)
{
std::size_t wpos = str.rfind(_T(' '));
if (_tstring::npos == wpos)
{
return;
}
const byte *beg = reinterpret_cast<const byte *>(str.c_str() + wpos + 1);
const byte *end = reinterpret_cast<const byte *>(str.c_str() + str.size());
#if 0
_tcout << std::hex;
std::ostream_iterator<byte, _TCHAR> oit(_tcout, _T(" ")); // Caution
std::copy(beg, end, oit);
_tcout << std::dec << std::endl;
#else
_tcout << std::setfill(_T('0')) << std::hex;
for (const byte *p = beg; p != end; ++p)
{
if (*p <= 0x7f && std::isprint(static_cast<char>(*p)))
{
_tcout << static_cast<char>(*p);
}
else
{
// In non-unicode mode, if we want to print the value of '*p'
// in hexadecimal format, we have to cast it into an integer.
_tcout << _T("\\x") << std::setw(2) << static_cast<int>(*p);
}
}
_tcout << std::setfill(_T(' ')) << std::dec << std::endl;
#endif
}
示例11: LoadObj
bool XPropBgObj::LoadObj( XEXmlNode& nodeObj, XGAME::xtBgObj type, LPCTSTR szTag )
{
// LPCTSTR szTag = XFORMAT("type=%d", type );
XEXmlNode nodeEach = nodeObj.GetFirst();
bool bOk = true;
while( !nodeEach.IsEmpty() ) {
const std::string strcName = nodeEach.GetcstrName();
if( strcName == "each" ) {
const _tstring strTag = C2SZ(strcName);
auto pProp = LoadEach( nodeEach, type, strTag.c_str() );
if( pProp ) {
pProp->m_strSpr = nodeObj.GetTString( "spr" );
// if( type != xBOT_SOUND ) {
if( XBREAK(pProp->m_strSpr.empty()) ) {
PROP_LOG("error: spr is empty");
}
// }
AddBgObj( pProp );
}
} else {
PROP_LOG( "%s: 알수없는 노드", C2SZ(strcName.c_str()) )
}
//
nodeEach = nodeEach.GetNext();
}
return bOk;
}
示例12: XWnd
XWndTextString::XWndTextString( const XE::VEC2& vPos,
const _tstring& strString,
const _tstring& strFont,
float sizeFont,
XCOLOR col )
: XWnd( vPos.x, vPos.y )
{
Init();
Create( XE::VEC2(0), strString.c_str(), strFont, sizeFont, col );
}
示例13: StripLeading
_tstring StripLeading(const _tstring &source, const char toStrip)
{
const TCHAR *pSrc = source.c_str();
while (pSrc && *pSrc == toStrip)
{
++pSrc;
}
return pSrc;
}
示例14:
//---------------------------------------------------------------------
// 再帰的にディレクトリを作成するCreateDirectory関数
//---------------------------------------------------------------------
bool kjm::util::create_directory(const _tstring& path) {
// 指定フォルダがルートを指しているときは、正常終了
if (PathIsRoot(path.c_str())) {
return true;
}
// すでにフォルダが存在するので、正常終了
if (PathFileExists(path.c_str())) {
return true;
}
// 親フォルダの作成を試みる
TCHAR work[MAX_PATH];
PathAppend(lstrcpy(work, path.c_str()), _T(".."));
if (kjm::util::create_directory(work)) {
if (CreateDirectory(path.c_str(), NULL)) {
return true;
}
}
return false;
}
示例15: LinkShader
BOOL XShader::LinkShader( GLuint prog, const char *cszTag )
{
GLint status;
glLinkProgram( prog );
GLint logLength;
glGetProgramiv( prog, GL_INFO_LOG_LENGTH, &logLength );
if( logLength > 0 ) {
GLchar *log = (GLchar *)malloc( logLength );
glGetProgramInfoLog( prog, logLength, &logLength, log );
if( logLength > 0 ) {
const _tstring strTag = C2SZ( cszTag );
const _tstring strLog = C2SZ( log );
XTRACE( "Program link log:\n %s\n [%s]\n", strTag.c_str(), strLog.c_str() );
}
free( log );
}
glGetProgramiv( prog, GL_LINK_STATUS, &status );
if( status == 0 ) {
return NO;
}
return YES;
}