背景:在linux下读取文件内容,按照WIndows下的代码一直提示错误Segmentation fault (core dumped),最后发现linux下读取是有区别的不能直接使用WIndows下的代码
实现代码如下
std::ifstream f(filename.c_str());
char csvLine[100]={0};//重要!!! 100 一般设为一行的最大长度f.getline(csvLine,100);//skip table header
std::string str1,str2,modelid,name,xmlid;
while (f.getline(csvLine,100))
{
stringstream word(csvLine);
//buildingid buildingname modelid roomtype schemeid
word>>str1;
word>>str2;
word>>modelid;
word>>name;
word>>xmlid;
//ok 将文件中的列的信息读取出来
}
f.close();