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


C++ ConfigSection::getDouble方法代码示例

本文整理汇总了C++中ConfigSection::getDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigSection::getDouble方法的具体用法?C++ ConfigSection::getDouble怎么用?C++ ConfigSection::getDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigSection的用法示例。


在下文中一共展示了ConfigSection::getDouble方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
	Random rnd;
	// Some test values
	int intValue = rnd.nextInt(5,16);
	float floatValue = rnd.nextFloat() * 100.0F - 50.0F;
	double doubleValue = rnd.nextDouble() * 100.0 - 25.0;
	const char* filename = "test.cf";

	int intValue2 = rnd.nextInt(17, 32);
	float floatValue2 = 1000.0F + rnd.nextFloat() * 100.0F - 50.0F;
	double doubleValue2 = 100.0 + rnd.nextDouble() * 100.0 - 25.0;



	cout << "Config tester program. Using file " << filename << " for testing." << endl;
	cout << "  Version " << VERSION << endl;

	const size_t d_array_size = 8;
	const int d_array_values[] = {0,1,2,3,4,8,14,-5};

	// Create test config file
	cout << "Creating test file ... " << endl;
	ofstream of(filename);
	of << "      test = none" << endl;
	of << endl;
	of << "int = " << intValue << endl;
	of << "test = test" << endl;
	of << "float = " << floatValue << endl;
	of << "Illegal line" << endl;
	of << "  double = " << doubleValue << endl;
	of << "# double = " << (doubleValue * 500.0) << endl;
	of << "  notdouble = 0affd" << endl;
	{
		// Write array
		of << "d_array = ";
		bool first = true;
		for(size_t i=0;i<d_array_size;i++) {
			if (first) first = false;
			else of << ',';
			of << d_array_values[i];
		}
		of << endl;
	}
	of << endl;
	of << "[section]" << endl;
	of << "int = " << intValue2 << endl;
	of << "#double = " << (doubleValue2+2.0) << endl;
	of << "double = " << doubleValue2 << endl;
	of << "float = " << floatValue2 << endl;
	of.close();


	// Read config file
	cout << "Reading config ... " << endl;
	Config config(filename);
	int errors = 0;

	if(!config.readSuccessfull()) {
		cerr << "Cannot read config file" << endl;
		return EXIT_FAILURE;
	}

	// Check values
	bool ok;
	cout << "Checking values ... " << endl;
	if(config.getInt("int", 0, &ok) != intValue) {
		errors++;
		cerr << "  Error reading int value. Expected: " << intValue << ", read: " << config.getInt("int", 0) << endl;
	} else {
		if(!ok) {
			errors++;
			cerr << "  Error in the OK variable. Ok = false although the readout was successful" << endl;
		}
	}
	if(config.getInt("int", 0, ok) != intValue) {
		errors++;
		cerr << "  Error reading int value. Expected: " << intValue << ", read: " << config.getInt("int", 0) << endl;
	}
	if(!fequal(config.getFloat("float", 0), floatValue)) {
		errors++;
		cerr << "  Error reading float value. Expected: " << floatValue << ", read: " << config.getFloat("float", 0.0) << endl;
	}
	if(!fequal(config.getFloat("float", 0, ok), floatValue)) {
		errors++;
		cerr << "  Error reading float value. Expected: " << floatValue << ", read: " << config.getFloat("float", 0.0) << endl;
	}
	if(!fequal(config.getDouble("double", 0), doubleValue)) {
		errors++;
		cerr << "  Error reading double value" << endl;
	}
	if(!fequal(config.getDouble("double", 0, ok), doubleValue)) {
		errors++;
		cerr << "  Error reading double value" << endl;
	}
	if(config("test") != "test") {
		errors++;
		cerr << "  Error reading test string value" << endl;
		cerr << "  \"test\" != \"" << config("test") << "\"" << endl;
	}
	if(!fequal(config.getDouble("notdouble", doubleValue), doubleValue)) {
//.........这里部分代码省略.........
开发者ID:grisu48,项目名称:FlexLib2,代码行数:101,代码来源:config.cpp


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