本文整理汇总了C++中std::basic_string::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::c_str方法的具体用法?C++ basic_string::c_str怎么用?C++ basic_string::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: r
std::string ws2s(const std::basic_string<WCHAR> & s) {
size_t slength = (int)s.length() + 1;
size_t len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
std::string r(len, '\0');
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, &r[0], len, 0, 0);
return r;
}
示例2: OnExportPresetButton
long CMetronomeDlg_RegPersist::OnExportPresetButton(unsigned long const nIgnore1, long const nIgnore2)
{
OPENFILENAME ofn;
TCHAR szE[] = _T("/e \"");
TCHAR szR[] = _T("\" \"HKEY_CURRENT_USER\\Software\\BHBSoftware\\Open Metronome\"");
TCHAR szWholeFile[MAX_PATH + sizeof(szE) + sizeof(szR)] = _T(""); // buffer for file name
TCHAR szFile[255]; // buffer for file name
TCHAR title[255]; //buffer for file title
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hWnd;
ofn.lpstrFile = szFile;
ofn.lpstrFileTitle = title;
//
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = (TCHAR)'\0';
ofn.lpstrDefExt = _T("REG");
ofn.lpstrFileTitle[0] = (TCHAR)'\0';
ofn.nMaxFile = sizeof(szFile);
ofn.nMaxFileTitle = sizeof(title);
#ifdef USE_WEIRD_MIDI
ofn.lpstrFilter = _T("Registry Files (*.REG)\0*.REG\0\0");
#else //USE_WEIRD_WAV
ofn.lpstrFilter = _T("Wave Sound (*.WAV)\0*.WAV\0Registry Files (*.REG)\0*.REG\0\0");
#endif
ofn.nFilterIndex = 1;
ofn.Flags = OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn) == IDOK)
{
std::basic_string<TCHAR> const strFilename(ofn.lpstrFile);
if (_tcsstr(_tcsupr(ofn.lpstrFile), _T(".WAV"))-ofn.lpstrFile == strFilename.length()-4)
{
if (BuildPlayerInstance())
{
if (m_autopTicker.get())
{
m_autopTicker->Export(strFilename.c_str(), m_NumExp);
m_autopTicker = (std::auto_ptr<IBeatBox>) NULL;
}
}
}
#ifndef UNDER_CE
else
{
_tcscpy(szWholeFile, szE);
_tcscat(szWholeFile, strFilename.c_str());
_tcscat(szWholeFile, szR);
ShellExecute(this->m_hWnd, _T("open"), _T("regedit"), szWholeFile, 0, SW_SHOWNORMAL);
}
#endif
}
return 0;
}
示例3: FromFile
void FromFile(const std::basic_string<WCHAR>& pathW)
{
DWORD wtf;
DWORD size;
Translations.clear();
size = GetFileVersionInfoSizeW(pathW.c_str(), &wtf);
if(!size)
return;
data.resize(size);
if(!GetFileVersionInfoW(pathW.c_str(), 0, size, data.data()))
return;
// fixed info (main shit)
VS_FIXEDFILEINFO* ffi = 0;
UINT ffilen = 0;
if(!VerQueryValueW(data.data(), L"\\", (void**)&ffi, &ffilen))
return;
m_a = HIWORD(ffi->dwFileVersionMS);
m_b = LOWORD(ffi->dwFileVersionMS);
m_c = HIWORD(ffi->dwProductVersionLS);
m_d = LOWORD(ffi->dwProductVersionLS);
// Read the list of languages and code pages.
LANGANDCODEPAGE* lpTranslate;
VerQueryValueW(data.data(), L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &ffilen);
for(unsigned i = 0; i < (ffilen / sizeof(LANGANDCODEPAGE)); i++)
{
Translations.push_back(lpTranslate[i]);
}
}
示例4: lock
std::basic_string< char > str_convert< char, wchar_t >( std::basic_string< wchar_t > const & src )
{
std::basic_string< char > dst;
if ( !src.empty() )
{
std::unique_lock< std::mutex > lock( g_conversionMutex );
char * szloc = setlocale( LC_CTYPE, "" );
size_t size = wcstombs( NULL, src.c_str(), 0 ) + 1;
char * buffer = NULL;
{
auto guard = make_block_guard( [&buffer, &size]()
{
buffer = new char[size + 1];
}, [&buffer]()
{
delete [] buffer;
} );
size = std::min( size, wcstombs( buffer, src.c_str(), size ) );
setlocale( LC_CTYPE, szloc );
dst.assign( buffer, buffer + size );
}
}
return dst;
}
示例5: mb_button_to_button_type
inline button_type::type message_box(
HWND hwnd, const std::basic_string<T>& message,
const std::basic_string<T>& title, box_type::type box,
icon_type::type icon, unsigned int default_button, bool show_help)
{
unsigned int type = 0;
type |= detail::box_type_to_mb_box(box);
type |= detail::icon_type_to_mb_icon(icon);
unsigned int max_default_button = button_count_from_box_type(box);
if (show_help)
{
type |= MB_HELP;
max_default_button++;
}
if (default_button > max_default_button)
BOOST_THROW_EXCEPTION(
std::invalid_argument("Default button out-of-range"));
type |= default_to_mb_default(default_button);
int rc = native::message_box(
hwnd, message.c_str(), title.c_str(), type);
if (rc == 0)
BOOST_THROW_EXCEPTION(
boost::enable_error_info(washer::last_error()) <<
boost::errinfo_api_function("MessageBox"));
return detail::mb_button_to_button_type(rc);
}
示例6: TokenizerTest
void TokenizerTest()
{
const std::basic_string<utf16_t> xmlText =
Transcoder::UTF8toUTF16("<token1><token2 />\nhello world.\nhello xml.</token1>");
XMLParser<utf16_t>::Tokenizer tokenizer(xmlText.c_str(), xmlText.c_str() + xmlText.size());
std::basic_string<utf16_t> result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("<token1>"));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("<token2 />"));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("\nhello world.\nhello xml."));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("</token1>"));
CPPUNIT_ASSERT(tokenizer.isEof());
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16(""));
CPPUNIT_ASSERT(tokenizer.isEof());
}
示例7: test_normc
void test_normc(std::basic_string<Char> orig,std::basic_string<Char> normal,boost::locale::norm_type type)
{
std::locale l = boost::locale::generator().generate("en_US.UTF-8");
TEST(boost::locale::normalize(orig,type,l)==normal);
TEST(boost::locale::normalize(orig.c_str(),type,l)==normal);
TEST(boost::locale::normalize(orig.c_str(),orig.c_str()+orig.size(),type,l)==normal);
}
示例8: mv
// if TCHAR is defined as WCHAR, we have to do unicode conversion
void mv(std::string& lhs, const std::basic_string<WCHAR>& rhs) {
auto size_needed = WideCharToMultiByte(CP_UTF8, 0, rhs.c_str(),
static_cast<int>(rhs.size()),
nullptr, 0, nullptr, nullptr);
lhs.resize(size_needed);
WideCharToMultiByte(CP_UTF8, 0, rhs.c_str(), static_cast<int>(rhs.size()),
&lhs[0], size_needed, nullptr, nullptr);
}
示例9: associate
/* ------------------------------------------------------------------------- */
void associate(const std::basic_string<TCHAR>& key, const std::basic_string<TCHAR>& value, bool flag) {
static const TCHAR* clsid_associate = _T("{F3DB85F4-4731-4e80-BC2E-754A7320D830}");
static const TCHAR* clsid_tooltip = _T("{00021500-0000-0000-C000-000000000046}");
HKEY subkey;
LONG status = RegOpenKeyEx(HKEY_CLASSES_ROOT, ( key + _T( "\\shellex" ) ).c_str(), 0, KEY_ALL_ACCESS, &subkey );
if( !status ) {
RegDeleteKeyNT( subkey, clsid_tooltip );
RegCloseKey( subkey );
}
if (flag) {
DWORD disposition = 0;
LONG status = RegCreateKeyEx(HKEY_CLASSES_ROOT, key.c_str(), 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &subkey, &disposition);
if (!status) {
TCHAR buffer[32] = {};
DWORD type = 0;
DWORD size = sizeof(buffer);
if (RegQueryValueEx(subkey, _T(""), NULL, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && std::basic_string<TCHAR>(buffer) != value) {
RegSetValueEx(subkey, CUBEICE_REG_PREVARCHIVER, 0, REG_SZ, (CONST BYTE*)buffer, (_tcslen(buffer) + 1) * sizeof(TCHAR));
}
RegSetValueEx(subkey, _T(""), 0, REG_SZ, (CONST BYTE*)value.c_str(), (value.size() + 1) * sizeof(TCHAR));
disposition = 0;
status = RegCreateKeyEx(HKEY_CLASSES_ROOT, ( key + _T( "\\shellex\\") + clsid_tooltip ).c_str(), 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &subkey, &disposition);
if (!status) {
RegSetValueEx(subkey, _T(""), 0, REG_SZ, (CONST BYTE*)clsid_associate, (_tcslen(clsid_associate) + 1) * sizeof(TCHAR));
}
}
}
else {
LONG status = RegOpenKeyEx(HKEY_CLASSES_ROOT, key.c_str(), 0, KEY_ALL_ACCESS, &subkey);
if (!status) {
TCHAR buffer[32] = {};
DWORD type = 0;
DWORD size = sizeof(buffer);
if (RegQueryValueEx(subkey, _T(""), NULL, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && std::basic_string<TCHAR>(buffer) == value) {
TCHAR prev[32] = {};
type = 0;
size = sizeof(prev);
if (RegQueryValueEx(subkey, CUBEICE_REG_PREVARCHIVER, NULL, &type, (LPBYTE)prev, &size) == ERROR_SUCCESS) {
RegSetValueEx(subkey, _T(""), 0, REG_SZ, (CONST BYTE*)prev, (_tcslen(prev) + 1) * sizeof(TCHAR));
}
else {
RegCloseKey(subkey);
RegDeleteKeyNT(HKEY_CLASSES_ROOT, key.c_str());
}
}
}
}
}
示例10: ShellExecute
Error ShellExecute(const std::basic_string<charT, traits, Allocator>& fileName = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& operation = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& parameters = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& directory = std::basic_string<charT, traits, Allocator>(),
HWND hwnd = HWND(NULL),
show_command showCmd = show_command_normal)
{
const charT * const file = fileName.c_str();
const charT * const op = operation.empty() ? NULL : operation.c_str();
const charT * const params = parameters.empty() ? NULL : parameters.c_str();
const charT * const dir = directory.empty() ? NULL : directory.c_str();
return ShellExecute(hwnd, op, file, params, dir, showCmd);
}
示例11:
std::basic_string<CharType> parent_path(const std::basic_string<CharType>& path)
{
auto index = path.size();
if (index)
{
auto str = path.c_str();
for (--index; index > 0; --index)
{
auto c = str[index];
if (c != '\\' && c != '/')
break;
}
for (--index; index > 0; --index)
{
auto c = str[index];
if (c == '\\' || c == '/')
break;
}
}
return index ? path.substr(0, index + 1) : std::basic_string<CharType>();
}
示例12: if
void read_config
(
const std::basic_string<Ch>& a_filename,
basic_variant_tree<Ch>& a_tree,
const boost::function<bool (std::basic_string<Ch>& a_filename)>
a_resolver = inc_file_resolver<Ch>(),
int a_flags = 0,
const std::locale & a_loc = std::locale(),
config_format a_fmt = FORMAT_UNDEFINED
) {
std::basic_string<Ch> ext = boost::filesystem::extension(a_filename);
if (a_fmt == FORMAT_UNDEFINED) {
if (ext == ".config" || ext == ".conf" || ext == ".cfg" || ext == ".scon")
a_fmt = FORMAT_SCON;
else if (ext == ".ini")
a_fmt = FORMAT_INI;
else if (ext == ".xml")
a_fmt = FORMAT_XML;
else
throw std::runtime_error("Configuration file extension not supported!");
}
std::basic_ifstream<Ch> stream(a_filename.c_str());
if (!stream)
throw variant_tree_parser_error(
"cannot open file for reading", a_filename, 0);
stream.imbue(a_loc);
read_config(stream, a_tree, a_fmt, a_filename, a_resolver, a_flags);
}
示例13: string_generate
inline bool string_generate(OutputIterator& sink
, std::basic_string<Char, Traits, Allocator> const& str
, CharEncoding, Tag)
{
return string_generate(sink, str.c_str()
, encoding_filter<CharEncoding, Tag>());
}
示例14: ReportError
/*
* ReportError
*
* Report an error to the user
*/
void ReportError( std::basic_string<TCHAR> message,
DWORD reason)
{
LPTSTR error_string;
if (reason != ERROR_SUCCESS)
{
if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
reason,
0,
(LPTSTR)&error_string,
0,
NULL) != 0)
{
LPTSTR p = _tcschr(error_string, _T('\r'));
if(p != NULL)
{
*p = _T('\0');
}
message += _T(":\n");
message += error_string;
::LocalFree(error_string);
}
}
::MessageBox(NULL,message.c_str(),_T("AES Crypt Error"), MB_OK);
}
示例15: unzip
inline bool unzip(const BufferT &inBuf, const std::basic_string<TCHAR> &path)
{
auto_zip hz = ::OpenZip(inBuf.first.get(), inBuf.second, ZIP_MEMORY, path.c_str());
if( !hz.IsValid() )
return false;
ZIPENTRYW ze = {0};
HRESULT hRes = ::GetZipItem(hz, -1 ,&ze);
if( hRes != S_OK )
return false;
int numitems = ze.index;
for(int i=0; i != numitems; ++i)
{
hRes = ::GetZipItem(hz,i, &ze);
if( hRes != S_OK )
return false;
hRes = ::UnzipItem(hz, i, ze.name, 0, ZIP_FILENAME);
if( hRes != S_OK )
return false;
}
return true;
}