当前位置: 首页>>代码示例>>C++>>正文


C++ std::locale方法代码示例

本文整理汇总了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;
}
开发者ID:Kirija,项目名称:XPIR,代码行数:25,代码来源:french.cpp

示例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';
}
开发者ID:minh0722,项目名称:vitosha,代码行数:19,代码来源:french.cpp

示例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;
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:15,代码来源:test_xml_parser_rapidxml.cpp

示例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();
};
开发者ID:lijin1989422,项目名称:compare_spreadsheet,代码行数:45,代码来源:ReportEntity.cpp

示例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
//.........这里部分代码省略.........
开发者ID:sashavolv2,项目名称:tasbot,代码行数:101,代码来源:main.cpp

示例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;
			}
//.........这里部分代码省略.........
开发者ID:GerbilSoft,项目名称:rom-properties,代码行数:101,代码来源:rpcli.cpp

示例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.

//.........这里部分代码省略.........
开发者ID:cpascal,项目名称:af-cpp,代码行数:101,代码来源:nonfinite_facet_simple.cpp


注:本文中的std::locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。