本文整理汇总了C++中std::wstring::capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::capacity方法的具体用法?C++ wstring::capacity怎么用?C++ wstring::capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::capacity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_file2
void load_file2(std::wstring& wstrOut, std::wistream& wistreamIn)
{
wstrOut.erase();
//bad() 如果出现错误则返回true
if(wistreamIn.bad())
return;
wstrOut.reserve(wistreamIn.rdbuf()->in_avail());
wchar_t c;
//get() 读取字符
while(wistreamIn.get(c))
{
if(wstrOut.capacity() == wstrOut.size())
wstrOut.reserve(wstrOut.capacity() * 3);
wstrOut.append(1, c);
}
}
示例2: func
void func (std::string a, std::wstring b)
{
printf ("%s\n", a.c_str());
printf ("%d\n", a.size());
printf ("%d\n", a.capacity());
wprintf (L"%s\n", b.c_str());
printf ("%d\n", b.size());
printf ("%d\n", b.capacity());
};
示例3: DownloadWebPageUnicode
BOOL DownloadWebPageUnicode(std::wstring& page, HINTERNET hInternet, LPCWSTR url)
{
TRACEST(_T("DownloadWebPageUnicode"), CW2CT(url));
BOOL bDownloadSuccess = FALSE;
if (hInternet == NULL)
return FALSE;
HINTERNET hFile = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
if (hFile)
{
page.clear();
DWORD dwSize = 0;
INT headerCP = 0;//Latin1
INT pageCP = 0;//Latin1
INT workingCP = 1252;//Latin1
if(!HttpQueryInfo(hFile, HTTP_QUERY_RAW_HEADERS_CRLF, 0, &dwSize, 0))
{
if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
{
SetLastError(0);
LPVOID lpOutBuffer = new CHAR[dwSize];
if (HttpQueryInfo(hFile, HTTP_QUERY_RAW_HEADERS_CRLF, lpOutBuffer, &dwSize, 0))
{
//TRACE((LPCTSTR)lpOutBuffer);
headerCP = GetWindowsCodePageW((LPCTSTR)lpOutBuffer);
}
delete[] lpOutBuffer;
}
}
DWORD pageSize = 0;
DWORD pageSizeLen = sizeof(pageSize);
if (::HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, &pageSize, &pageSizeLen, NULL))
{
if (pageSize > 0)
page.reserve(pageSize + 10);
}
if (page.capacity() < 1000)
page.reserve(50000);
const int bufferSize = 8192;
const int bufferSizeU = 2 * bufferSize;
CHAR bf[bufferSize + 1];
TCHAR bfU[bufferSizeU];
unsigned long nSize = 0;
BOOL bReadSuccess = TRUE;
BOOL bFirstTime = TRUE;
while(bReadSuccess)
{
bReadSuccess = InternetReadFile(hFile, bf, bufferSize, &nSize);
if (bReadSuccess)
{
if (nSize == 0)
{
//TRACE(_T("@3 DownloadWebPage. InternetReadFile Finished\r\n"));
bDownloadSuccess = TRUE;
break;
}
if (bFirstTime)
{
bFirstTime = FALSE;
bf[nSize] = 0;
pageCP = GetWindowsCodePageA(bf);
if (headerCP != pageCP)
{
TRACE(_T("@3 DownloadWebPage. CodePage Differs (header:%d - page:%d)\r\n"),
headerCP, pageCP);
}
if (pageCP > 0) //===Choose the Codepage detected from page if available
workingCP = pageCP;
else if (headerCP > 0) //===Else select the Codepage detected from headers if available
workingCP = headerCP;
//===Otherwise keep the original 1252 (latin 1)
}
if (nSize > 0)
{
INT bfLen = MultiByteToWideChar(workingCP, 0, bf, nSize, 0, 0);
if (bfLen < bufferSizeU)
{
MultiByteToWideChar(workingCP, 0, bf, nSize, bfU, bfLen);
page.append(bfU, bfLen);
}
else
{
TRACE(_T("@1 DownloadWebPageUnicode. Unicode buffer not enough\r\n"));
bReadSuccess = FALSE;
}
}
}
else
HandleInternetError(_T("DownloadWebPageUnicode. InternetReadFile"));
}
InternetCloseHandle(hFile);
}
else
HandleInternetError(_T("DownloadWebPageUnicode. InternetOpenUrl"));
return bDownloadSuccess;
}