本文整理汇总了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;
}