本文整理匯總了C++中string_t::c_str方法的典型用法代碼示例。如果您正苦於以下問題:C++ string_t::c_str方法的具體用法?C++ string_t::c_str怎麽用?C++ string_t::c_str使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類string_t
的用法示例。
在下文中一共展示了string_t::c_str方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: readdir
void pal::readdir(const string_t& path, const string_t& pattern, std::vector<pal::string_t>* list)
{
assert(list != nullptr);
std::vector<string_t>& files = *list;
string_t search_string(path);
append_path(&search_string, pattern.c_str());
WIN32_FIND_DATAW data = { 0 };
auto handle = ::FindFirstFileExW(search_string.c_str(), FindExInfoStandard, &data, FindExSearchNameMatch, NULL, 0);
if (handle == INVALID_HANDLE_VALUE)
{
return;
}
do
{
string_t filepath(data.cFileName);
files.push_back(filepath);
} while (::FindNextFileW(handle, &data));
::FindClose(handle);
}
示例2: init
void
logger_t::_log(
char const * file,
int line,
level_t level,
string_t const & message
) {
init();
string_t thread = ( _thread == NULL ? "master" : _thread->name() );
string_t prefix = _prefix;
if ( prefix.substr( 0, thread.size() + 2 ) == thread + ": " ) {
prefix.erase( 0, thread.size() + 2 );
};
syslog(
levels[ level ].id,
"%s %s(%s) %s%s",
levels[ level ].name,
location( file, line ).c_str(),
thread.c_str(),
prefix.c_str(),
message.c_str()
);
}; // _log
示例3: SaveToFile
bool SaveToFile(LPCVOID data, DWORD length, const string_t& path,
bool take_backup) {
// Make sure the path is available
CreateFolder(GetPathOnly(path));
// Take a backup if needed
if (take_backup) {
std::wstring new_path = path + L".bak";
MoveFileEx(path.c_str(), new_path.c_str(),
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
}
// Save the data
BOOL result = FALSE;
HANDLE file_handle = OpenFileForGenericWrite(path);
if (file_handle != INVALID_HANDLE_VALUE) {
DWORD bytes_written = 0;
result = ::WriteFile(file_handle, data, length, &bytes_written, nullptr);
::CloseHandle(file_handle);
}
return result != FALSE;
}
示例4: selectMatch
int selectMatch(const string_t& name)
{
LV_FINDINFO findInfo = { sizeof(LV_FINDINFO) };
findInfo.flags = LVFI_STRING;
findInfo.psz = name.c_str();
int itemPos = list_.FindItem(&findInfo, -1);
if (itemPos == -1)
return itemPos;
UINT flags = list_.GetItemState(itemPos, LVIS_SELECTED);
//if (!flags && LVIS_SELECTED)
{
LVITEM lvi = { LVIF_STATE };
lvi.state = LVIS_SELECTED;
lvi.stateMask = LVIS_SELECTED;
list_.SetItemState(itemPos, &lvi);
}
return itemPos;
}
示例5: save
bool save(const string_t& path, const trainer_states_t& states)
{
std::ofstream ofs(path.c_str(), std::ofstream::out);
if (!ofs.is_open())
{
return false;
}
const string_t delim = "\t";
const size_t colsize = 24;
// header
ofs
<< text::resize("train-loss", colsize) << delim
<< text::resize("train-error-average", colsize) << delim
<< text::resize("train-error-variance", colsize) << delim
<< text::resize("valid-loss", colsize) << delim
<< text::resize("valid-error-average", colsize) << delim
<< text::resize("valid-error-variance", colsize) << delim
<< std::endl;
// optimization states
for (const trainer_state_t& state : states)
{
ofs
<< text::resize(text::to_string(state.m_tvalue), colsize) << delim
<< text::resize(text::to_string(state.m_terror_avg), colsize) << delim
<< text::resize(text::to_string(state.m_terror_var), colsize) << delim
<< text::resize(text::to_string(state.m_vvalue), colsize) << delim
<< text::resize(text::to_string(state.m_verror_avg), colsize) << delim
<< text::resize(text::to_string(state.m_verror_var), colsize) << delim
<< std::endl;
}
return ofs.good();
}
示例6: stop
void stop( string_t const & message ) {
printf( "%s\n", message.c_str() );
exit( 1 );
}
示例7:
D3DTexture::D3DTexture(D3DRenderContext& renderContext, const string_t& path) {
CGL_CHECK(D3DXCreateTextureFromFileA(renderContext.GetDevice(), path.c_str(), &m_texture) == D3D_OK);
}
示例8: DrawBitmapText
void TextureManager::DrawBitmapText(float sx, float sy, size_t tex, SpriteColor color, const string_t &str, enumAlignText align) const
{
// grep enum enumAlignText LT CT RT LC CC RC LB CB RB
static const float dx[] = { 0, 1, 2, 0, 1, 2, 0, 1, 2 };
static const float dy[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2 };
std::vector<size_t> lines;
size_t maxline = 0;
if( align )
{
size_t count = 0;
for( const string_t::value_type *tmp = str.c_str(); *tmp; )
{
++count;
++tmp;
if( '\n' == *tmp || '\0' == *tmp )
{
if( maxline < count )
maxline = count;
lines.push_back(count);
count = 0;
}
}
}
const LogicalTexture < = Get(tex);
size_t count = 0;
size_t line = 0;
float x0 = sx - floorf(dx[align] * (lt.pxFrameWidth - 1) * (float) maxline / 2);
float y0 = sy - floorf(dy[align] * lt.pxFrameHeight * (float) lines.size() / 2);
for( const string_t::value_type *tmp = str.c_str(); *tmp; ++tmp )
{
if( '\n' == *tmp )
{
++line;
count = 0;
}
if( (unsigned char) *tmp < 32 )
{
continue;
}
const FRECT &rt = lt.uvFrames[(unsigned char) *tmp - 32];
float x = x0 + (float) ((count++) * (lt.pxFrameWidth - 1));
float y = y0 + (float) (line * lt.pxFrameHeight);
MyVertex *v = g_render->DrawQuad(lt.dev_texture);
v[0].color = color;
v[0].u = rt.left;
v[0].v = rt.top;
v[0].x = x;
v[0].y = y ;
v[1].color = color;
v[1].u = rt.left + lt.uvFrameWidth;
v[1].v = rt.top;
v[1].x = x + lt.pxFrameWidth;
v[1].y = y;
v[2].color = color;
v[2].u = rt.left + lt.uvFrameWidth;
v[2].v = rt.bottom;
v[2].x = x + lt.pxFrameWidth;
v[2].y = y + lt.pxFrameHeight;
v[3].color = color;
v[3].u = rt.left;
v[3].v = rt.bottom;
v[3].x = x;
v[3].y = y + lt.pxFrameHeight;
}
}
示例9: LoadPackage
int TextureManager::LoadPackage(const string_t &packageName, const SafePtr<FS::MemMap> &file)
{
TRACE("Loading texture package '%s'", packageName.c_str());
lua_State *L = lua_open();
if( 0 != (luaL_loadbuffer(L, file->GetData(), file->GetSize(), packageName.c_str()) || lua_pcall(L, 0, 1, 0)) )
{
GetConsole().WriteLine(1, lua_tostring(L, -1));
lua_close(L);
return 0;
}
if( !lua_istable(L, 1) )
{
lua_close(L);
return 0;
}
// loop over files
for( lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1) )
{
// now 'key' is at index -2 and 'value' at index -1
// check that value is a table
if( !lua_istable(L, -1) )
{
TRACE("WARNING: value is not a table; skipping.");
}
while( lua_istable(L, -1) )
{
TexDescIterator td;
// get a file name; load
lua_getfield(L, -1, "file");
std::string f = lua_tostring(L, -1);
lua_pop(L, 1); // pop result of lua_getfield
try
{
LoadTexture(td, f);
}
catch( const std::exception &e )
{
TRACE("WARNING: could not load texture '%s' - %s", f.c_str(), e.what());
break;
}
// get 'content' field
lua_getfield(L, -1, "content");
if( lua_istable(L, -1) )
{
// loop over textures in 'content' table
for( lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1) )
{
if( !lua_istable(L, -1) )
{
TRACE("WARNING: element of 'content' is not a table; skipping");
continue;
}
lua_pushvalue(L, -2); // create copy of the key
if( const char *texname = lua_tostring(L, -1) )
{
// now 'value' at index -2
float scale_x = auxgetfloat(L, -2, "xscale", 1);
float scale_y = auxgetfloat(L, -2, "yscale", 1);
LogicalTexture tex;
tex.dev_texture = td->id;
// texture bounds
tex.uvLeft = (float) floorf(auxgetfloat(L, -2, "left", 0)) / (float) td->width;
tex.uvRight = (float) floorf(auxgetfloat(L, -2, "right", (float) td->width)) / (float) td->width;
tex.uvTop = (float) floorf(auxgetfloat(L, -2, "top", 0)) / (float) td->height;
tex.uvBottom = (float) floorf(auxgetfloat(L, -2, "bottom", (float) td->height)) / (float) td->height;
// frames count
tex.xframes = auxgetint(L, -2, "xframes", 1);
tex.yframes = auxgetint(L, -2, "yframes", 1);
// frame size
tex.uvFrameWidth = (tex.uvRight - tex.uvLeft) / (float) tex.xframes;
tex.uvFrameHeight = (tex.uvBottom - tex.uvTop) / (float) tex.yframes;
// original size
tex.pxFrameWidth = (float) td->width * scale_x * tex.uvFrameWidth;
tex.pxFrameHeight = (float) td->height * scale_y * tex.uvFrameHeight;
// pivot position
tex.uvPivot.x = (float) auxgetfloat(L, -2, "xpivot", (float) td->width * tex.uvFrameWidth / 2) / ((float) td->width * tex.uvFrameWidth);
tex.uvPivot.y = (float) auxgetfloat(L, -2, "ypivot", (float) td->height * tex.uvFrameHeight / 2) / ((float) td->height * tex.uvFrameHeight);
// frames
tex.uvFrames.reserve(tex.xframes * tex.yframes);
for( int y = 0; y < tex.yframes; ++y )
{
//.........這裏部分代碼省略.........
示例10: stringToDouble
double Utils::stringToDouble(string_t string)
{
return atof(string.c_str());
}
示例11: stringToFloat
float Utils::stringToFloat(string_t string)
{
return atof(string.c_str());
}
示例12: value
void value(const string_t& val)
{
node_->value(val.c_str());
}
示例13: SetOverlayIcon
void cTaskBar::SetOverlayIcon(HICON hIcon, const string_t& sDescription)
{
std::cout<<"cTaskBar::SetOverlayIcon"<<std::endl;
ASSERT(IsValid());
taskBarList->SetOverlayIcon(hwndWindow, hIcon, LPCWSTR(sDescription.c_str()));
}
示例14: are_paths_equal_with_normalized_casing
bool pal::are_paths_equal_with_normalized_casing(const string_t& path1, const string_t& path2)
{
// On Windows, paths are case-insensitive
return (strcasecmp(path1.c_str(), path2.c_str()) == 0);
}
示例15: StringToNum
extern
T Utils::StringToNum(string_t string)
{
return (T) atoi(string.c_str());
}