我对这个概念还很陌生,所以请多多包涵。我有一个包含许多列和行的csv文件,但是现在,我只想从测试文件中读取内容,以将我的类功能测试到我创建的结构中。这是我的结构:
int main()
{
typedef struct {
Date d;
Time t;
float speed;
}WindLogType;
Vector<WindLogType> windlog;
日期和时间是处理日期和时间值的类。 Vector是我创建的自定义矢量类,用于创建WindLogType类型的动态数组,我想将这些值存储在windlog中。
我的testfile.csv:
31/2/2014 23:45,55.6
日期和时间存储在一行中,逗号之后是浮起速度。我在类中使用了ignore语句来坚持这一点,但是我的困惑在于我如何将此文件读入Vector对象。这是我到目前为止所拥有的:
main.cpp:
int main()
{
typedef struct {
Date d;
Time t;
float speed;
}WindLogType;
Vector<WindLogType> windlog;
ifstream infile("testinput.csv");
if(!infile){
cout << "File not found.";
return -1;
};
infile >> windlog;
for(int i = 0; i < windlog.size(); i++){
cout << windlog[i] << endl;
}
我的Vector.h添加方法:
template <class T>
void Vector<T>::add(const T &obj){
if(this->nrofel >= this->capacity){
this->expand();
}
this->data[this->nrofel++] = new T(obj);
}
如何在Vector中使用我的add函数将值添加到Windlog中?