c++ 保存 .csv格式的文件很简单,那么怎么读取.csv表格数据呢,
FILE *pFile;
pFile = fopen("distanceData.csv", "r");
char readLine[1024];
int lineNo = 0;
Mat dataMat = Mat::zeros(ROWS,COLS,CV_32FC1);
while (1)
{
memset(readLine, 0, sizeof(readLine));
fgets(readLine, 1024, pFile);
string strLine(readLine), strTmp;
//cout << "ReadLine: " << strLine << endl;
stringstream ss(strLine);
string tmpStr;
vector<string> strStore;
while (getline(ss, tmpStr, ','))
strStore.push_back(tmpStr);
for (int i = 0; i < strStore.size(); ++i)
dataMat.at<float>(lineNo, i) = atof(strStore[i].c_str());// string 转 float
lineNo++;
if (feof(pFile))
break;
}