-1
我正在一個C++應用程序中讀取一個csv文件,並將內容存儲在雙精度矩陣和struct tm向量中。我有一些與此類似:如何使C++中的struct tm向量在strptime上工作?
#include <iostream>
#include <time.h>
#include <vector>
using namespace std;
int main(){
vector<struct tm> tmTM;
strptime("20020202", "%Y%m%d", &tmTM[0]);
cout << tmTM[0].tm_year << endl;
cout << tmTM[0].tm_mday << endl;
cout << tmTM[0].tm_mon << endl;
return 0;
}
Unfortunly這段代碼生成一個錯誤分割故障(核心轉儲) 我在C++初學者,所以我不知道什麼是錯的代碼。 非常感謝!
你的載體是空的,但你訪問它不存在的第一個元素。 – juanchopanza 2015-02-09 19:03:29
我應該使用這樣的memset嗎? 'memset(&tmTM [0],0,sizeof(struct tm));' – user3010850 2015-02-09 19:06:33
不知道如何使用'std :: vector'(或者其他任何你使用的庫代碼。非常安全。) – juanchopanza 2015-02-09 19:08:03