csv file to an object, c++
我有一个简单的csv文件:
1 2 3 | name,surname Joe,Moe Bob,Rob |
在javascript中,我只需按以下方式创建一个对象数组:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // let's assume the csv file is valid and it was already processed var csv = ["name","surname","Joe","Moe","Bob","Rob"], ret = [], i, ilen, j, o, cols = 2; for (i = cols, ilen = csv.length; i < ilen; i += cols) { o = {}; for (j = 0; j < cols; j += 1) { o[csv[j]] = csv[i + j]; } ret.push(o); } console.log(ret); // [{name:"Joe", surname:"Moe"}, {name:"Bob", surname:"Rob"}] |
我想创建一个填充了对象(类的实例)的向量。类需要在运行时生成,csv文件可能会更改。
你能指导如何在C++中实现这一点吗?
C++没有动态类型的概念,可以在运行时构建。您必须使用集合,如