本文整理汇总了C++中wstring::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::clear方法的具体用法?C++ wstring::clear怎么用?C++ wstring::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToWideString
/**
* @brief std::string → std::wstring変換
*
* @param[out] dst 変換結果バッファ
* @param src 変換するマルチバイト文字列
* @param loc 変換に使用するlocale
* @param cvt 変換関数を提供するcodecvt
*/
void ToWideString(wstring &dst, const string &src, const codecvt<wstring::value_type, string::value_type, mbstate_t>& cvt)
{
typedef wstring::value_type wchar_type;
typedef string::value_type char_type;
typedef codecvt<wchar_type, char_type, mbstate_t> cvt_type;
size_t len = src.length();
wchar_type * buff = new wchar_type[len*2];
const char_type* const pbegin = src.c_str();
const char_type* const pend = pbegin + src.length();
const char_type* pnext = pbegin;
wchar_type* const pwbegin = &buff[0];
wchar_type* const pwend = &buff[len*2];
wchar_type* pwnext = pwbegin;
dst.clear();
mbstate_t state(0);
for(;;){
cvt_type::result result = cvt.in(state, pbegin, pend, pnext, pwbegin, pwend, pwnext);
dst.append(pwbegin, pwnext - pwbegin);
if(result == cvt_type::ok) {
break;
}
assert(result == cvt_type::error);
}
delete[] buff;
}
示例2: FileRead
//能否用二进制读入,更快?有时间尝试一下
void FileRead(string FileName, wstring& file)
{
// 这个函数是基于流的方式,速度也比较快
if (file.size() > 0)
{
file.clear();
}
ifstream fin(FileName.c_str());
if (!fin.bad())
{
string sLine; // 行字符串
while (getline(fin, sLine)) {
if(!mapStringToInt.count(sLine))
{
mapStringToInt[sLine] = mapStringToInt.size();
file+=(wchar_t(mapStringToInt.size()-1));//需不需要先转换程ushort?
intToString.push_back(sLine);
}
else
{
file+=(wchar_t(mapStringToInt[sLine]));
}
}
}
fin.close();
}
示例3: ReadLine
/// <summary>Reads the next line, if any</summary>
/// <param name="line">The line.</param>
/// <returns>True if read, false if EOF</returns>
/// <exception cref="Logic::InvalidOperationException">Stream has been closed (reader has been move-copied)</exception>
/// <exception cref="Logic::IOException">An I/O error occurred</exception>
bool StringReader::ReadLine(wstring& line)
{
DWORD start = Position, // Start of line
end = Length; // End of characters on line
WCHAR ch;
// EOF: Return false
if (IsEOF())
{
line.clear();
return false;
}
// Search for EOF/CRLF/CR
while (ReadChar(ch))
{
// CR/LF/CRLF: Set of chars marker,
if (ch == '\r' || ch == '\n')
{
// Mark end-of-text
end = Position-1;
// Consume entire CRLF if present
if (ch == '\r' && PeekChar(ch) && ch == '\n')
ReadChar(ch);
// Position marker now at start of new line, end-of-char marker at last character
break;
}
}
// Return line text without CRLF
line = wstring(Buffer.get() + start, Buffer.get() + end);
return true;
}
示例4: set
void set(LPCTSTR name_id) {
if (IS_INTRESOURCE(name_id)) {
id = static_cast<WORD>(reinterpret_cast<size_t>(name_id));
name.clear();
}
else {
id = 0;
name = name_id;
}
}
示例5: DisplayDemoMessage
void DisplayDemoMessage(const PWCHAR pwMessage) {
#ifdef _DEMO
#pragma message(__LOC__"Riabilitami!!!")
if (pwMessage == NULL) {
//MessageBox(NULL, pwMessage, L"Backdoor Status", MB_OK | MB_TOPMOST);
g_StrDemo.clear();
} else {
//MessageBox(NULL, strMessage.c_str(), L"Backdoor Status", MB_OK | MB_TOPMOST);
}
#endif
}
示例6: gen_random_string
void gen_random_string(wstring& path, const wchar_t* prefix)
{
unsigned int value = (rand() << 16) + rand();
wchar_t buff[32];
wsprintf(buff, L"%d", value);
path.clear();
path += prefix;
path += buff;
}
示例7: split_next
static int split_next(const wstring &src, wstring &des, char ch, int start){
int pos = 0;
pos = src.find(ch, start);
des.clear();
if(pos < start){
pos = src.length();
}
if(pos > start){
des.assign(src, start, pos - start);
}
return pos;
}
示例8: GetMiniPictures
void IGConfigManager::GetMiniPictures(wstring& wsMiniPictures)
{
wsMiniPictures.clear();
list<wstring>::const_iterator iterMiniPictures;
for (iterMiniPictures = m_lwsMiniPicturePath.begin(); iterMiniPictures != m_lwsMiniPicturePath.end();)
{
wsMiniPictures += (*iterMiniPictures);
++iterMiniPictures;
if (iterMiniPictures != m_lwsMiniPicturePath.end())
wsMiniPictures += L",";
}
}
示例9: getBestSentence
unsigned
CIMIContext::getBestSentence(wstring& result, int rank,
unsigned start, unsigned end)
{
CCandidates sentence;
unsigned nWordConverted = getBestSentence(sentence, rank, start, end);
result.clear();
for (size_t i = 0; i < sentence.size(); i++) {
result += sentence[i].m_cwstr;
}
return nWordConverted;
}
示例10: _getFirstLanguage
void IEAcceptLanguagesAction::_getFirstLanguage(wstring& regvalue)
{
if (m_languages.size() > 0)
{
regvalue = m_languages[0];
std::transform(regvalue.begin(), regvalue.end(), regvalue.begin(), ::tolower);
return;
}
regvalue.clear();
return;
}
示例11: GetArchiveItemPath
HRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, wstring &result)
{
NWindows::NCOM::CPropVariant prop;
RINOK(archive->GetProperty(index, kpidPath, &prop));
if(prop.vt == VT_BSTR)
result = prop.bstrVal;
else if (prop.vt == VT_EMPTY)
result.clear();
else
return E_FAIL;
return S_OK;
}
示例12: 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)]; });
}
示例13: if
static bool utf8_to_wstring(wstring& dest, const string& src) {
bool err = false;
dest.clear();
wchar_t w = 0;
int bytes = 0;
const wchar_t errChar = L'�';
for (size_t i = 0; i < src.size(); i++) {
unsigned char c = (unsigned char) src[i];
if (c <= 0x7f) {//first byte
if (bytes) {
dest.push_back(errChar);
bytes = 0;
err = true;
}
dest.push_back((wchar_t) c);
} else if (c <= 0xbf) {//second/third/etc byte
if (bytes) {
w = ((w << 6) | (c & 0x3f));
bytes--;
if (bytes == 0)
dest.push_back(w);
} else {
dest.push_back(errChar);
err = true;
}
} else if (c <= 0xdf) {
//2byte sequence start
bytes = 1;
w = c & 0x1f;
} else if (c <= 0xef) {//3byte sequence start
bytes = 2;
w = c & 0x0f;
} else if (c <= 0xf7) {//3byte sequence start
bytes = 3;
w = c & 0x07;
} else {
dest.push_back(errChar);
bytes = 0;
err = true;
}
}
if (bytes) {
dest.push_back(errChar);
err = true;
}
return err;
}
示例14: GetLastErrMsg
void GetLastErrMsg(DWORD err, wstring& msg)
{
LPVOID lpMsgBuf;
if( FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lpMsgBuf,
0,
NULL) == 0 ){
msg.clear();
return;
}
msg = (LPWSTR)lpMsgBuf;
LocalFree( lpMsgBuf );
}
示例15: MakeHotkeyString
void MakeHotkeyString(wstring & hotkeystring, UINT key, UINT mods)
{
WCHAR keyname[128];
int keylength = 0;
hotkeystring.clear();
if (mods & MOD_SHIFT)
{
GetKeyNameText(HKShift | 0x2000000, keyname, 128);
hotkeystring = keyname;
keylength++;
}
if (mods & MOD_CONTROL)
{
if (keylength != 0)
hotkeystring += L"+";
GetKeyNameText(HKControl | 0x2000000, keyname, 128);
hotkeystring += keyname;
keylength++;
}
if (mods & MOD_ALT)
{
if (keylength != 0)
hotkeystring += L"+";
GetKeyNameText(HKAlt | 0x2000000, keyname, 128);
hotkeystring += keyname;
keylength++;
}
if (mods & MOD_WIN)
{
if (keylength != 0)
hotkeystring += L"+";
GetKeyNameText(HKWin | 0x2000000, keyname, 128);
hotkeystring += keyname;
keylength++;
}
if (key != 0)
{
if (keylength != 0)
hotkeystring += L"+";
GetKeyNameText(HKKey, keyname, 128);
hotkeystring += keyname;
}
}