1 Star 0 Fork 0

Ethan Tang/bomtree

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
columnnames.cpp 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
Ethan Tang 提交于 2014-08-08 14:59 . Release version
#include "columnnames.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
ColumnNames::ColumnNames()
{
}
bool ColumnNames::loadColumnNames(const char *datName)
{
colIndexMap.clear();
std::string colFilePath = "./ColumnNames/";
colFilePath += datName;
FILE* file = fopen(colFilePath.c_str(), "r");
if( !file )
{
return false;
}
while( !feof(file) )
{
int index = 0;
char cData[100];
if( fscanf( file, "%d %s",&index, cData ) == 2 )
{
index -= 1;
std::string colName = cData;
colIndexMap.insert( std::map< std::string, int >::value_type(colName, index) );
}
}
fclose(file);
return true;
}
unsigned int ColumnNames::getIndex(const char *colName)
{
std::string colStr = colName;
std::map< std::string, int >::iterator i = colIndexMap.find(colStr);
if( i != colIndexMap.end() )
{
return i->second;
}
std::cerr<<"Failed to get index of column "<<colName<<std::endl;
exit(1);
return 999999;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/stargate/bomtree.git
[email protected]:stargate/bomtree.git
stargate
bomtree
bomtree
master

搜索帮助