本文整理匯總了C++中std::locale方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::locale方法的具體用法?C++ std::locale怎麽用?C++ std::locale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::locale方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: main
int main()
{
using std::cout;
using std::locale;
using namespace boost;
using namespace boost::chrono;
#if BOOST_CHRONO_VERSION==2
cout.imbue(locale(locale(), new duration_units_fr<>()));
#else
cout.imbue(locale(locale(), new duration_punct<char>
(
duration_punct<char>::use_long,
"secondes", "minutes", "heures",
"s", "m", "h"
)));
#endif
hours h(5);
minutes m(45);
seconds s(15);
milliseconds ms(763);
cout << h << ", " << m << ", " << s << " et " << ms << '\n';
cout << hours(0) << ", " << minutes(0) << ", " << s << " et " << ms << '\n';
return 0;
}
示例2: main
int main()
{
using std::cout;
using std::locale;
using namespace boost;
using namespace boost::chrono;
cout.imbue(locale(locale(), new duration_punct<char>
(
duration_punct<char>::use_long,
"secondes", "minutes", "heures",
"s", "m", "h"
)));
hours h(5);
minutes m(45);
seconds s(15);
milliseconds ms(763);
cout << h << ", " << m << ", " << s << " et " << ms << '\n';
}
示例3: test_main
int test_main(int argc, char *argv[])
{
using namespace boost::property_tree;
test_xml_parser<ptree>();
test_xml_parser<iptree>();
#ifndef BOOST_NO_CWCHAR
using std::locale;
// We need a UTF-8-aware global locale now.
locale loc(locale(), new utf8_codecvt_facet);
locale::global(loc);
test_xml_parser<wptree>();
test_xml_parser<wiptree>();
#endif
return 0;
}
示例4: save
void ReportEntity::save(std::string filepath)
{
using std::locale;
//locale &loc=locale::global(locale(locale(),"",LC_CTYPE));
locale &loc=locale::global(locale("chs", locale::ctype));
std::ofstream fs(filepath, std::ios::out|std::ios::binary);
for(ReportHeader::iterator iter = this->m_header.begin();
iter != this->m_header.end(); ++iter)
{
const char * header_colname = iter->second.c_str();
fs << header_colname;
ReportHeader::iterator iter_check = iter;
if(++iter_check == this->m_header.end()){
fs << std::endl;
}else{
fs << ",";
}
}
for(Content::iterator iter = this->m_content.begin();
iter != this->m_content.end(); ++iter)
{
ReportRow& row = *iter;
for(ReportRow::iterator iter_r = row.begin();
iter_r != row.end(); ++ iter_r)
{
fs << iter_r->get()->toString();
if(iter_r+1 == row.end()){
fs << std::endl;
}else{
fs << ",";
}
}
}
locale::global(loc);
fs.close();
};
示例5: main
int main(int argc,char *argv[])
{
{
#ifdef MULTITHREAD_STDLOCALE_WORKAROUND
// Note: there's a known threading bug regarding std::locale with MSVC according to
// http://connect.microsoft.com/VisualStudio/feedback/details/492128/std-locale-constructor-modifies-global-locale-via-setlocale
int iPreviousFlag = ::_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
#endif
using std::locale;
locale::global(locale(locale::classic(), "", locale::collate | locale::ctype));
#ifdef MULTITHREAD_STDLOCALE_WORKAROUND
if (iPreviousFlag > 0 )
::_configthreadlocale(iPreviousFlag);
#endif
}
TASPlayer::Init();
SetThreadAffinityMask(GetCurrentThread(),1);
//printf("%08x",opsize); //AGAIN?!
char *t;
initArchiveSystem();
if(timeBeginPeriod(1) != TIMERR_NOERROR)
{
AddLogText("Error setting timer granularity to 1ms.", DO_ADD_NEWLINE);
}
InitCommonControls();
debugSystem = new DebugSystem();
if(!FCEUI_Initialize())
{
do_exit();
return 1;
}
ApplyDefaultCommandMapping();
fceu_hInstance = GetModuleHandle(0);
fceu_hAccel = LoadAccelerators(fceu_hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1));
// Get the base directory
GetBaseDirectory();
// load fceux.cfg
sprintf(TempArray,"%s\\%s",BaseDirectory.c_str(),cfgFile.c_str());
LoadConfig(TempArray);
//initDirectories();
// Parse the commandline arguments
t = ParseArgies(argc, argv);
int saved_pal_setting = !!pal_emulation;
if (ConfigToLoad)
{
// alternative config file specified
cfgFile.assign(ConfigToLoad);
// Load the config information
sprintf(TempArray,"%s\\%s",BaseDirectory.c_str(),cfgFile.c_str());
LoadConfig(TempArray);
}
//Bleh, need to find a better place for this.
{
FCEUI_SetGameGenie(genie!=0);
fullscreen = !!fullscreen;
soundo = !!soundo;
frame_display = !!frame_display;
allowUDLR = !!allowUDLR;
pauseAfterPlayback = !!pauseAfterPlayback;
closeFinishedMovie = !!closeFinishedMovie;
EnableBackgroundInput = !!EnableBackgroundInput;
KeyboardSetBackgroundAccess(EnableBackgroundInput!=0);
JoystickSetBackgroundAccess(EnableBackgroundInput!=0);
FCEUI_SetSoundVolume(soundvolume);
FCEUI_SetSoundQuality(soundquality);
FCEUI_SetTriangleVolume(soundTrianglevol);
FCEUI_SetSquare1Volume(soundSquare1vol);
FCEUI_SetSquare2Volume(soundSquare2vol);
FCEUI_SetNoiseVolume(soundNoisevol);
FCEUI_SetPCMVolume(soundPCMvol);
}
//Since a game doesn't have to be loaded before the GUI can be used, make
//sure the temporary input type variables are set.
ParseGIInput(NULL);
// Initialize default directories
//.........這裏部分代碼省略.........
示例6: main
int RP_C_API main(int argc, char *argv[])
{
#ifdef _WIN32
// Set Win32 security options.
secoptions_init();
#endif /* _WIN32 */
// Set the C and C++ locales.
locale::global(locale(""));
#if defined(_MSC_VER) && defined(ENABLE_NLS)
// Delay load verification.
// TODO: Only if linked with /DELAYLOAD?
if (DelayLoad_test_textdomain() != 0) {
// Delay load failed.
// TODO: Use a CMake macro for the soversion?
#define LIBGNUINTL_DLL "libgnuintl-8.dll"
fputs("*** ERROR: " LIBGNUINTL_DLL " could not be loaded.\n\n"
"This build of rom-properties has localization enabled,\n"
"which requires the use of GNU gettext.\n\n"
"Please redownload rom-properties and copy the\n"
LIBGNUINTL_DLL " file to the installation directory.\n",
stderr);
return EXIT_FAILURE;
}
#endif /* defined(_MSC_VER) && defined(ENABLE_NLS) */
// Initialize i18n.
rp_i18n_init();
if(argc < 2){
#ifdef ENABLE_DECRYPTION
cerr << C_("rpcli", "Usage: rpcli [-k] [-c] [-j] [[-x[b]N outfile]... [-a apngoutfile] filename]...") << endl;
cerr << " -k: " << C_("rpcli", "Verify encryption keys in keys.conf.") << endl;
#else /* !ENABLE_DECRYPTION */
cerr << C_("rpcli", "Usage: rpcli [-j] [[-x[b]N outfile]... [-a apngoutfile] filename]...") << endl;
#endif /* ENABLE_DECRYPTION */
cerr << " -c: " << C_("rpcli", "Print system region information.") << endl;
cerr << " -j: " << C_("rpcli", "Use JSON output format.") << endl;
cerr << " -xN: " << C_("rpcli", "Extract image N to outfile in PNG format.") << endl;
cerr << " -a: " << C_("rpcli", "Extract the animated icon to outfile in APNG format.") << endl;
cerr << endl;
cerr << C_("rpcli", "Examples:") << endl;
cerr << "* rpcli s3.gen" << endl;
cerr << "\t " << C_("rpcli", "displays info about s3.gen") << endl;
cerr << "* rpcli -x0 icon.png pokeb2.nds" << endl;
cerr << "\t " << C_("rpcli", "extracts icon from pokeb2.nds") << endl;
}
assert(RomData::IMG_INT_MIN == 0);
// DoFile parameters
bool json = false;
vector<ExtractParam> extract;
for (int i = 1; i < argc; i++) { // figure out the json mode in advance
if (argv[i][0] == '-' && argv[i][1] == 'j') {
json = true;
}
}
if (json) cout << "[\n";
bool first = true;
int ret = 0;
for(int i=1;i<argc;i++){
if(argv[i][0] == '-'){
switch (argv[i][1]) {
#ifdef ENABLE_DECRYPTION
case 'k': {
// Verify encryption keys.
static bool hasVerifiedKeys = false;
if (!hasVerifiedKeys) {
hasVerifiedKeys = true;
ret = VerifyKeys();
}
break;
}
#endif /* ENABLE_DECRYPTION */
case 'c': {
// Print the system region information.
PrintSystemRegion();
break;
}
case 'x': {
ExtractParam ep;
long num = atol(argv[i] + 2);
if (num<RomData::IMG_INT_MIN || num>RomData::IMG_INT_MAX) {
cerr << rp_sprintf(C_("rpcli", "Warning: skipping unknown image type %ld"), num) << endl;
i++; continue;
}
ep.image_type = num;
ep.filename = argv[++i];
extract.push_back(ep);
break;
}
case 'a': {
ExtractParam ep;
ep.image_type = -1;
ep.filename = argv[++i];
extract.push_back(ep);
break;
}
//.........這裏部分代碼省略.........
示例7: main
int main ()
{
std::cout << "Nonfinite_num_facet very simple example." << std::endl;
if((std::numeric_limits<double>::has_infinity == 0) || (std::numeric_limits<double>::infinity() == 0))
{
std::cout << "Infinity not supported on this platform." << std::endl;
return 0;
}
if((std::numeric_limits<double>::has_quiet_NaN == 0) || (std::numeric_limits<double>::quiet_NaN() == 0))
{
std::cout << "NaN not supported on this platform." << std::endl;
return 0;
}
std::locale default_locale (std::locale::classic ()); // Note the currrent (default C) locale.
// Create plus and minus infinity.
double plus_infinity = +std::numeric_limits<double>::infinity();
double minus_infinity = -std::numeric_limits<double>::infinity();
// and create a NaN (NotANumber)
double NaN = +std::numeric_limits<double>::quiet_NaN ();
double negated_NaN = (boost::math::changesign)(std::numeric_limits<double>::quiet_NaN ());
// Output the nonfinite values using the current (default C) locale.
// The default representations differ from system to system,
// for example, using Microsoft compilers, 1.#INF, -1.#INF, and 1.#QNAN.
cout << "Using C locale" << endl;
cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl;
cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl;
cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl;
// Display negated NaN.
cout << "negated NaN " << negated_NaN << endl; // "-1.IND"
// Create a new output locale, and add the nonfinite_num_put facet
std::locale C99_out_locale (default_locale, new boost::math::nonfinite_num_put<char>);
// and imbue the cout stream with the new locale.
cout.imbue (C99_out_locale);
// Or for the same effect more concisely:
cout.imbue (locale(locale(), new boost::math::nonfinite_num_put<char>));
// Output using the new locale
cout << "Using C99_out_locale " << endl;
cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl;
cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl;
cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl;
// Display negated NaN.
cout << "negated NaN " << negated_NaN << endl; // -nan
// Create a string with the expected C99 representation of plus infinity.
std::string inf = "inf";
{ // Try to read an infinity value using the default C locale.
// Create an input stream which will provide "inf"
std::istringstream iss (inf);
// Create a double ready to take the input,
double infinity;
// and read "inf" from the stringstream:
iss >> infinity;
// This will not work on all platforms!
if (! iss)
{ // Reading infinity went wrong!
std::cerr << "C locale input format error!" << std::endl;
}
} // Using default C locale.
{ // Now retry using C99 facets.
// Create a new input locale and add the nonfinite_num_get facet.
std::locale C99_in_locale (default_locale, new boost::math::nonfinite_num_get<char>);
// Create an input stream which will provide "inf".
std::istringstream iss (inf);
// Imbue the stream with the C99 input locale.
iss.imbue (C99_in_locale);
// Create a double ready to take the input,
double infinity;
// and read from the stringstream:
iss >> infinity;
if (! iss)
{ // Reading infinity went wrong!
std::cout << "C99 input format error!" << std::endl;
}
// Expect to get an infinity, which will display still using the C99 locale as "inf"
cout << "infinity in C99 representation is " << infinity << endl;
// To check, we can switch back to the default C locale.
cout.imbue (default_locale);
cout << "infinity in default C representation is " << infinity << endl;
} // using C99 locale.
//.........這裏部分代碼省略.........