本文整理汇总了C++中wstring::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::reserve方法的具体用法?C++ wstring::reserve怎么用?C++ wstring::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::reserve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
//----------------------------------------------------------------------
// Converts a UTF8 encoded string to a unicode string
// See the following document for more information:
// RFC2279: UTF-8, a transformation format of ISO 10646
// Author: pdaehne
//----------------------------------------------------------------------
void TextFace::convertUTF8ToUnicode(const string &utf8Text, wstring &text)
{
// Clear and prepare the result string
text.erase();
text.reserve(utf8Text.length());
// Transform UTF8 sequences to UTF16 sequences
const char *pos = utf8Text.c_str();
while (*pos != '\0')
text.append(1, utf8Char2Unicode(pos));
}
示例2: generate
void RandomStringGenerator::generate(wstring &str) {
static const wchar_t alphabet[] =
L"abcdefghijklmnopqrstuvwxyz"
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
L"0123456789";
random_device rd;
default_random_engine rng(rd());
uniform_int_distribution<> dist(0,sizeof(alphabet)/sizeof(*alphabet)-2);
str.clear();
str.reserve(NAME_LENGTH);
generate_n(back_inserter(str), NAME_LENGTH,
[&] { return alphabet[dist(rng)]; });
}
示例3: do_log
static void do_log(int log_level, const char *msg, va_list args, void *param)
{
fstream &logFile = *static_cast<fstream*>(param);
char str[4096];
#ifndef _WIN32
va_list args2;
va_copy(args2, args);
#endif
vsnprintf(str, 4095, msg, args);
#ifdef _WIN32
if (IsDebuggerPresent()) {
int wNum = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (wNum > 1) {
static wstring wide_buf;
static mutex wide_mutex;
lock_guard<mutex> lock(wide_mutex);
wide_buf.reserve(wNum + 1);
wide_buf.resize(wNum - 1);
MultiByteToWideChar(CP_UTF8, 0, str, -1, &wide_buf[0],
wNum);
wide_buf.push_back('\n');
OutputDebugStringW(wide_buf.c_str());
}
}
#else
def_log_handler(log_level, msg, args2, nullptr);
#endif
if (too_many_repeated_entries(logFile, msg, str))
return;
if (log_level <= LOG_INFO || log_verbose)
LogStringChunk(logFile, str);
#if defined(_WIN32) && defined(OBS_DEBUGBREAK_ON_ERROR)
if (log_level <= LOG_ERROR && IsDebuggerPresent())
__debugbreak();
#endif
}
示例4: FPSCounter
//FPS Counter
void FPSCounter(HINSTANCE hInstance)
{
static int frames = 0;
static double starttime = CTimeManager::GetElapsedTimeD();
static float fps = 0.0f;
if (CTimeManager::GetElapsedTimeD() - starttime > 0.25 && frames > 10)
{
fps_string.clear();
fps_string.reserve(MAX_LOADSTRING);
fps_string = szTitle;
fps = float((double)frames / double(CTimeManager::GetElapsedTimeD() - starttime));
starttime = CTimeManager::GetElapsedTimeD();
frames = 0;
fps_string += L" FPS: ";
wchar_t temp[32];
_snwprintf_s(temp, 32u, L"%f", fps);
fps_string += temp;
SendMessage(hWnd, WM_SETTEXT, NULL, (LPARAM)fps_string.data());
}
frames++;
}