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


C++ CDatabase::Add方法代码示例

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


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

示例1:

void
CCar::clone_into (CDatabase &db) const
{
	for (int i = 0; i < m_LogNr; i++)
	{
		const TLog &log = m_Log[i];
		db.Add (log.m_Date,
			log.m_Driver->m_Name, log.m_Driver->m_Surname, m_RZ);
	}
}
开发者ID:mikesma,项目名称:fit-cvut,代码行数:10,代码来源:ukol04.cpp

示例2: name

int
main (int argc, char *argv[])
{
	CDatabase *a, *b, *c;

	a = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-03", "John", "Nowak", "DEF-56-67"));
	assert (a->Add ("2012-03-02", "George", "Smith", "DEF-56-67"));

	cout << *a;
	cout << a->FindCar ("ABC-12-34");
	cout << a->FindDriver ("John", "Nowak");

	try {
		cout << a->FindCar ("XYZ-99-88");
		abort ();
	} catch (const InvalidCarException &e) {
		ostringstream ss;
		ss << e;
		assert (ss.str () == "XYZ-99-88");
	}

	try {
		cout << a->FindDriver ("John", "Smith");
		abort ();
	} catch (const InvalidDriverException &e) {
		ostringstream ss;
		ss << e;
		assert (ss.str () == "John Smith");
	}

	delete a;


	a = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "George", "Smith", "DEF-56-67"));
	cout << *a;
	assert (!a->Add ("2012-03-01", "John", "Nowak", "XYZ-99-99"));
	assert (!a->Add ("2012-03-02", "Peter", "McDonald", "DEF-56-67"));
	cout << *a;

	delete a;


	a = new CDatabase;
	b = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "John", "Nowak", "DEF-56-67"));
	assert (a->Add ("2012-03-01", "George", "Smith", "DEF-56-67"));
	assert (a->Add ("2012-03-02", "George", "Smith", "ABC-12-34"));
	cout << *a;

	*b = *a;
	c = new CDatabase (*a);
	assert (b->Add ("2012-03-03", "Homer", "Simpson", "ABC-12-34"));
	assert (c->Add ("2012-03-03", "Homer", "Simpson", "DEF-56-67"));
	delete a;
	cout << *b;
	cout << *c;

	delete b;
	delete c;


	CDatabase *db;

	db = new CDatabase;
	const char *names[] = {"A", "B", "C", "D", "E", "F"};
	char buf[40];
	srand (8);
	for (int i = 1000; i < 2000; i++)
	{
		string rz = "ABC-";
		sprintf (buf, "%d", rand () % 100);
		rz += buf;

		string name (names[rand () % 6]);
		string surname (names[rand () % 6]);

		string date = "2012-";
		sprintf (buf, "%d", i);
		date += buf;

		db->Add (date, name, surname, rz);
	}

	ostringstream outa, outb;
	outa << *db;
	outb << CDatabase (*db);
	assert (outa.str () == outb.str ());

	delete db;

	return 0;
}
开发者ID:mikesma,项目名称:fit-cvut,代码行数:98,代码来源:ukol04.cpp


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