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


C++ TABLE::push_back方法代码示例

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


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

示例1: read

// TABLE = vector<map <string, string> >
// File name should include path
TABLE lbCSV::read(std::string fileName)
{
	TABLE table;
	INFO("Attempting to load CSV file: " << fileName);

	std::ifstream file(fileName);

	std::string line = "";	

	// Catergories
	std::vector<std::string> keys;
	std::vector<std::string> data;
	std::map<std::string, std::string> inter;

	if (file.good())
	{
		INFO("CSV file is good.");
		
		// Get template line, ignoring any comments
		while (keys.size() == 0)
		{
			getline(file, line);
			keys = splitLine(line);
		}

		// Used just to output message
		std::string debugKeys = "";
		for (unsigned i = 0; i < keys.size(); i++)
		{
			debugKeys += keys[i] + ", ";
		}
		INFO("Loaded CSV keys: " << debugKeys);

		// Get all the other lines
		while (getline (file, line))
		{
			data = splitLine(line);
			// Make sure it's not an empty line
			if (data.size() > 0)
			{
				if (data.size() != keys.size())
				{
					ERROR("Number of data in line does not equal number of keys: #keys=" << keys.size() << ", #vals=" << data.size());
					break;
				}
				for (unsigned i = 0; i < data.size(); i++)
				{
					inter[keys[i]] = data[i];
				}

				// Add line to the full list
				table.push_back(inter);
				inter.clear();
			}
		}

		// always remember to close your files kids
		file.close();
	} else {
		ERROR("Could not open CSV file: " << fileName);
	}

	return table;
}
开发者ID:Samuel-Lewis,项目名称:Crypt,代码行数:66,代码来源:lbCSV.cpp


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