#include<string>
#include<iostream>
#include<fstream>
#include<sstream>
/********************************************************
* @function : KVSaveAsCsvFile
* @brief : 保存csv文件
*********************************************************/
inline void KVSaveAsCsvFile(const string& szFileName, const CObArray& ObjectArray)
{
ofstream outFile;
outFile.open(szFileName.c_str(), ios::ate|ios::out/*ios::app|ios::out*/); // 打开模式可省略
int nCount = ObjectArray.GetCount();
PTagAttribute pTagAttribute = NULL;
string szTagValue = "";
for (int nIndex = 0; nIndex < nCount - 1; ++nIndex)
{
pTagAttribute = (PTagAttribute)ObjectArray[nIndex];
szTagValue = MesCStringToString(CString((char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(pTagAttribute->strTagValue)).ToPointer()));
outFile << szTagValue << ",";
}
pTagAttribute = (PTagAttribute)ObjectArray[nCount - 1];
szTagValue = MesCStringToString(CString((char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(pTagAttribute->strTagValue)).ToPointer()));
outFile << szTagValue << "\n";
outFile.close();
}
/********************************************************
* @function : KVSaveAsCsvFile
* @brief : 保存csv文件
*********************************************************/
inline void KVReadCsvFile(CObArray& ObjectArray)
{
ifstream fin("data.csv"); //打开文件流操作
string strLineInfo = "";
int nIndex = 0;
while (getline(fin, strLineInfo)) //整行读取,换行符“\n”区分,遇到文件尾标志eof终止读取
{
istringstream sin(strLineInfo); //将整行字符串line读入到字符串流istringstream中
string info = "";
while (getline(sin, info, ',')) //将字符串流sin中的字符读入到Waypoints字符串中,以逗号为分隔符
{
PTagAttribute pTagAttribute = (PTagAttribute)ObjectArray[nIndex];
pTagAttribute->strTagValue = gcnew String(info.c_str());
}
}
fin.close();
}