本文整理汇总了C++中std::wstring::data方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::data方法的具体用法?C++ wstring::data怎么用?C++ wstring::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FolderExists
// 判断目录是否存在
BOOL CCommonInterface::FolderExists(std::wstring s)
{
DWORD attr;
attr = GetFileAttributes(s.data());
return (attr != (DWORD)(-1)) && (attr & FILE_ATTRIBUTE_DIRECTORY);
}
示例2: main
int main()
{
{
std::locale l("en_US");
{
typedef std::ctype<wchar_t> F;
const F& f = std::use_facet<F>(l);
const std::wstring in(L"\x00DA A\x07.a1");
std::vector<F::mask> m(in.size());
assert(f.scan_is(F::space, in.data(), in.data() + in.size()) - in.data() == 1);
assert(f.scan_is(F::print, in.data(), in.data() + in.size()) - in.data() == 0);
assert(f.scan_is(F::cntrl, in.data(), in.data() + in.size()) - in.data() == 3);
assert(f.scan_is(F::upper, in.data(), in.data() + in.size()) - in.data() == 0);
assert(f.scan_is(F::lower, in.data(), in.data() + in.size()) - in.data() == 5);
assert(f.scan_is(F::alpha, in.data(), in.data() + in.size()) - in.data() == 0);
assert(f.scan_is(F::digit, in.data(), in.data() + in.size()) - in.data() == 6);
assert(f.scan_is(F::punct, in.data(), in.data() + in.size()) - in.data() == 4);
assert(f.scan_is(F::xdigit, in.data(), in.data() + in.size()) - in.data() == 2);
assert(f.scan_is(F::blank, in.data(), in.data() + in.size()) - in.data() == 1);
assert(f.scan_is(F::alnum, in.data(), in.data() + in.size()) - in.data() == 0);
assert(f.scan_is(F::graph, in.data(), in.data() + in.size()) - in.data() == 0);
}
}
{
std::locale l("C");
{
typedef std::ctype<wchar_t> F;
const F& f = std::use_facet<F>(l);
const std::wstring in(L"\x00DA A\x07.a1");
std::vector<F::mask> m(in.size());
assert(f.scan_is(F::space, in.data(), in.data() + in.size()) - in.data() == 1);
assert(f.scan_is(F::print, in.data(), in.data() + in.size()) - in.data() == 1);
assert(f.scan_is(F::cntrl, in.data(), in.data() + in.size()) - in.data() == 3);
assert(f.scan_is(F::upper, in.data(), in.data() + in.size()) - in.data() == 2);
assert(f.scan_is(F::lower, in.data(), in.data() + in.size()) - in.data() == 5);
assert(f.scan_is(F::alpha, in.data(), in.data() + in.size()) - in.data() == 2);
assert(f.scan_is(F::digit, in.data(), in.data() + in.size()) - in.data() == 6);
assert(f.scan_is(F::punct, in.data(), in.data() + in.size()) - in.data() == 4);
assert(f.scan_is(F::xdigit, in.data(), in.data() + in.size()) - in.data() == 2);
assert(f.scan_is(F::blank, in.data(), in.data() + in.size()) - in.data() == 1);
assert(f.scan_is(F::alnum, in.data(), in.data() + in.size()) - in.data() == 2);
assert(f.scan_is(F::graph, in.data(), in.data() + in.size()) - in.data() == 2);
}
}
}
示例3: TestTimePut
/*
%a Abbreviated weekday name * Thu
%A Full weekday name * Thursday
%b Abbreviated month name * Aug
%B Full month name * August
%c Date and time representation * Thu Aug 23 14:55:02 2001
%C Year divided by 100 and truncated to integer (00-99) 20
%d Day of the month, zero-padded (01-31) 23
%D Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
%e Day of the month, space-padded ( 1-31) 23
%F Short YYYY-MM-DD date, equivalent to %Y-%m-%d 2001-08-23
%g Week-based year, last two digits (00-99) 01
%G Week-based year 2001
%h Abbreviated month name * (same as %b) Aug
%H Hour in 24h format (00-23) 14
%I Hour in 12h format (01-12) 02
%j Day of the year (001-366) 235
%m Month as a decimal number (01-12) 08
%M Minute (00-59) 55
%n New-line character ('\n')
%p AM or PM designation PM
%r 12-hour clock time * 02:55:02 pm
%R 24-hour HH:MM time, equivalent to %H:%M 14:55
%S Second (00-61) 02
%t Horizontal-tab character ('\t')
%T ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S 14:55:02
%u ISO 8601 weekday as number with Monday as 1 (1-7) 4
%U Week number with the first Sunday as the first day of week one (00-53) 33
%V ISO 8601 week number (00-53) 34
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
%W Week number with the first Monday as the first day of week one (00-53) 34
%x Date representation * 08/23/01
%X Time representation * 14:55:02
%y Year, last two digits (00-99) 01
%Y Year 2001
%z ISO 8601 offset from UTC in timezone (1 minute=1, 1 hour=100)
If timezone cannot be termined, no characters +100
%Z Timezone name or abbreviation *
If timezone cannot be termined, no characters CDT
%% A % sign %
*/
void TestTimePut()
{
auto now = std::chrono::system_clock::now();
auto t = std::chrono::system_clock::to_time_t(now);
std::wcout<<L"Local Time:"<<std::endl;
auto ptm = std::localtime(&t);
#if defined _WIN32
/* Windows dosen't support the time zone */
const std::wstring FMT(L"%Y-%m-%d %H:%M:%S %A\n");
#else
const std::wstring FMT(L"%Y-%m-%d %H:%M:%S %A %Z\n");
#endif
//const std::time_put<char>& ctp = std::use_facet<std::time_put<char> >(std::locale("C"));
//const std::time_put<char>& dtp = std::use_facet<std::time_put<char> >(std::locale());
//const std::time_put<char>& ntp = std::use_facet<std::time_put<char> >(std::locale(""));
//ctp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());
//dtp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());
//ntp.put(std::wcout, std::wcout, '0', ptm, FMT.data(), FMT.data() + FMT.length());
std::locale curlocale = std::wcout.getloc();
try
{
std::wcout<<L"C Locale:";
std::use_facet<std::time_put<wchar_t> >(std::locale("C")).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());
std::wcout<<L"Default Locale:";
std::use_facet<std::time_put<wchar_t> >(std::locale()).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());
std::wcout<<L"Native Locale:";
std::use_facet<std::time_put<wchar_t> >(std::locale("")).put(std::wcout, std::wcout, L'0', ptm, FMT.data(), FMT.data() + FMT.length());
if (std::wcout.bad())
{
std::wcout.clear();
std::wcout.flush();
std::wcout<<"Reset std::wcout"<<std::endl;
}
}
catch (...)
{
std::wcerr<<std::strerror(errno)<<std::endl;
}
std::wcout.imbue(curlocale);
}
示例4: parseLibFile
int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring& libname)
{
info.clear();
char* pstFile = wide_string_to_UTF8(_wstXML.data());
if (FileExist(pstFile) == FALSE)
{
FREE(pstFile);
return 1;
}
char *encoding = GetXmlFileEncoding(pstFile);
/* Don't care about line return / empty line */
xmlKeepBlanksDefault(0);
/* check if the XML file has been encoded with utf8 (unicode) or not */
if (stricmp("utf-8", encoding))
{
FREE(pstFile);
free(encoding);
return NULL;
}
xmlDocPtr doc;
xmlXPathContextPtr xpathCtxt = NULL;
xmlXPathObjectPtr xpathObj = NULL;
wchar_t* pstName = NULL;
wchar_t* pstLibName = NULL;
wchar_t* pstFileName = NULL;
wchar_t* pstMd5 = NULL;
free(encoding);
doc = xmlParseFile(pstFile);
if (doc == NULL)
{
FREE(pstFile);
return 1;
}
FREE(pstFile);
xpathCtxt = xmlXPathNewContext(doc);
xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
if (xpathObj && xpathObj->nodesetval->nodeMax)
{
xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
{
/* we found the tag name */
const char *str = (const char*)attrib->children->content;
pstLibName = to_wide_string(str);
libname = pstLibName;
FREE(pstLibName);
xmlXPathFreeObject(xpathObj);
}
else
{
if (xpathCtxt)
{
xmlXPathFreeContext(xpathCtxt);
}
xmlXPathFreeObject(xpathObj);
return 1;
}
}
xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
if (xpathObj && xpathObj->nodesetval->nodeMax)
{
/* the Xpath has been understood and there are node */
for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
{
xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
/* Get the properties of <module> */
while (attrib != NULL)
{
/* loop until when have read all the attributes */
if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
{
/* we found the tag name */
const char *str = (const char*)attrib->children->content;
pstName = to_wide_string(str);
}
else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
{
/* we found the tag activate */
const char *str = (const char*)attrib->children->content;
pstFileName = to_wide_string(str);
}
else if (xmlStrEqual(attrib->name, (const xmlChar*)"md5"))
{
/* we found the tag activate */
const char *str = (const char*)attrib->children->content;
pstMd5 = to_wide_string(str);
}
attrib = attrib->next;
}
//.........这里部分代码省略.........
示例5: test
void test(const std::wstring& s1, const std::wstring& s2) {
std::locale loc(std::locale(), new xxd::collate_dict_es());
const std::collate<wchar_t>& col = std::use_facet<std::collate<wchar_t> >(loc);
std::wcout << col.compare(s1.data(), s1.data()+s1.size(), s2.data(), s2.data()+s2.size()) << std::endl;
}
示例6:
//
// Converts wchar_t sequence into UTF-8 string
//
std::string convertWCHARtoUTF8(const std::wstring & str)
{
return convertWCHARtoUTF8(str.data(), str.length());
}
示例7:
INT64 StringUtility::WStringToInt64( std::wstring str )
{
INT64 i;
i = _wtoi64(str.data());
return i;
}
示例8: fileDiary
/*--------------------------------------------------------------------------*/
Diary::Diary(const std::wstring& _wfilename, int _mode, int ID, bool autorename)
{
std::ios::openmode wofstream_mode;
std::wstring fullfilename = getUniqueFilename(_wfilename);
if (autorename)
{
fullfilename = getUniqueFilename(_wfilename);
wchar_t* ws = getFullFilenameW(fullfilename.data());
fullfilename = ws;
FREE(ws);
}
else
{
wchar_t* ws = getFullFilenameW(_wfilename.data());
fullfilename = ws;
FREE(ws);
}
suspendwrite = false;
PrefixTimeFormat = PREFIX_TIME_FORMAT_UNIX_EPOCH;
IoModeFilter = DIARY_FILTER_INPUT_AND_OUTPUT; // default command & input
PrefixIoModeFilter = PREFIX_FILTER_NONE; // no prefix
if (_mode == 0)
{
wofstream_mode = std::ios::trunc | std::ios::binary;
}
else
{
wofstream_mode = std::ios::app | std::ios::binary;
}
#ifdef _MSC_VER
std::wofstream fileDiary(fullfilename, wofstream_mode);
#else
wchar_t *wcfile = (wchar_t *) fullfilename.c_str();
char *filename = wide_string_to_UTF8(wcfile);
std::ofstream fileDiary(filename, wofstream_mode);
if (filename)
{
FREE(filename);
filename = NULL;
}
#endif
if (fileDiary.bad())
{
wfilename = std::wstring(L"");
fileAttribMode = -1;
setID(-1);
}
else
{
wfilename = fullfilename;
fileAttribMode = wofstream_mode;
setID(ID);
}
fileDiary.close();
}
示例9: StringToLong
long StringUtility::StringToLong( std::wstring str )
{
long n = 0;
n = _wtol(str.data());
return n;
}
示例10: WSTringToInt
int StringUtility::WSTringToInt( std::wstring str )
{
int n = 0;
n = _wtoi(str.data());
return n;
}
示例11: catch
static int
run_test (int, char**)
{
// find all installed locales for which setlocale(LC_ALL) succeeds
const char* const locale_list =
rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
// array of locale names to use for testing
const char* locales [sizeof punct_data / sizeof *punct_data];
const std::size_t maxinx = sizeof locales / sizeof *locales;
// iterate over locales, initializing a global punct_data array
for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
std::locale loc;
MoneypunctData* const pdata = punct_data + nlocales;
pdata->locale_name_ = name;
locales [nlocales] = name;
try {
loc = std::locale (name);
typedef std::moneypunct<char, false> Punct;
const Punct &mp = std::use_facet<Punct>(loc);
const char dp = mp.decimal_point ();
const char ts = mp.thousands_sep ();
const std::string grp = mp.grouping ();
const std::string cur = mp.curr_symbol ();
const std::string pos = mp.positive_sign ();
const std::string neg = mp.negative_sign ();
const int fd = mp.frac_digits ();
const Punct::pattern pfm = mp.pos_format ();
const Punct::pattern nfm = mp.neg_format ();
pdata->decimal_point_ = dp;
pdata->thousands_sep_ = ts;
pdata->frac_digits_ = fd;
std::strcpy (pdata->grouping_, grp.c_str ());
std::strcpy (pdata->curr_symbol_, cur.c_str ());
std::strcpy (pdata->positive_sign_, pos.c_str ());
std::strcpy (pdata->negative_sign_, neg.c_str ());
std::memcpy (pdata->pos_format_, &pfm, sizeof pfm);
std::memcpy (pdata->neg_format_, &nfm, sizeof nfm);
}
catch (...) {
rw_warn (0, 0, __LINE__,
"std::locale(%#s) threw an exception, skipping", name);
continue;
}
try {
typedef std::moneypunct<char, true> Punct;
const Punct &mp = std::use_facet<Punct>(loc);
const std::string cur = mp.curr_symbol ();
const int fd = mp.frac_digits ();
const Punct::pattern pfm = mp.pos_format ();
const Punct::pattern nfm = mp.neg_format ();
pdata->int_frac_digits_ = fd;
std::strcpy (pdata->int_curr_symbol_, cur.c_str ());
std::memcpy (pdata->int_pos_format_, &pfm, sizeof pfm);
std::memcpy (pdata->int_neg_format_, &nfm, sizeof nfm);
}
catch (...) {
rw_warn (0, 0, __LINE__,
"std::locale(%#s) threw an exception, skipping", name);
continue;
}
#ifndef _RWSTD_NO_WCHAR_T
try {
typedef std::moneypunct<wchar_t, false> Punct;
const Punct &mp = std::use_facet<Punct>(loc);
const wchar_t dp = mp.decimal_point ();
const wchar_t ts = mp.thousands_sep ();
const std::wstring cur = mp.curr_symbol ();
const std::wstring pos = mp.positive_sign ();
const std::wstring neg = mp.negative_sign ();
pdata->wdecimal_point_ = dp;
pdata->wthousands_sep_ = ts;
typedef std::wstring::traits_type Traits;
Traits::copy (pdata->wcurr_symbol_, cur.data (), cur.size ());
Traits::copy (pdata->wpositive_sign_, pos.data (), pos.size ());
Traits::copy (pdata->wnegative_sign_, neg.data (), neg.size ());
}
//.........这里部分代码省略.........
示例12: format
static void format(reckless::output_buffer* pbuffer, std::wstring const& s)
{
pbuffer->write(s.data(), sizeof(wchar_t)*s.size());
}
示例13: database_error
void sqlite3_command::bind(int index, const std::wstring &data) {
if(sqlite3_bind_text16(this->stmt, index, data.data(), (int)data.length()*2, SQLITE_STATIC)!=SQLITE_OK)
throw database_error(&m_con);
}
示例14: ComputeHash
Std_String HashMD5Impl::GetStringHash(std::wstring strValue)
{
int nLen = strValue.size() * sizeof(wchar_t);
const unsigned char* pBuf = (const unsigned char*)strValue.data();
return ComputeHash(pBuf, nLen);
}
示例15:
System::String^ FP::Cloud::OnlineRateTable::PCalcLib::Convert::ToString(std::wstring source)
{
System::IntPtr _ep = (IntPtr)(wchar_t*)source.data();
String^ result = Marshal::PtrToStringUni(_ep);;
return result;
}