2014. 12. 8. 16:29ㆍ기타/Windows 개발
간단한 텍스트 파일 입출력 예제가 만드는 것 때문에 헤맸다.
http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=722007&ref=721961
try
{
file.Open(_T("testAddr.csv"), CFile::modeRead | CFile::shareDenyNone);
}
catch (CException* e)
{
e->Delete();
return FALSE;
}
char szBufRead[4096] = {0,};
char szBufData[4096] = {0,};
int nSizeRead;
int nIndex = 0;
int i;
while((nSizeRead = file.Read(szBufRead, 4095)) != NULL)
{
for(i = 0; i < nSizeRead; i++)
{
*(szBufData + nIndex) = *(szBufRead + i);
nIndex++;
if(*(szBufRead + i) == '\n')
{
szBufData[nIndex] = '\0';
DataParser(szBufData);
nIndex = 0;
}
}
}
if(nIndex != 0)
{
szBufData[nIndex] = '\0';
DataParser(szBufData);
}
file.Close();
szBufData는 DataParser()함수에서 CString에 대입되게 되어있습니다.
=============================================================================================
try
{
file.Open(_T("testAddr.csv"), CFile::modeCreate | CFile::modeWrite);
for(int i = 0; i < m_nCurrentDbIndex; i++)
{
str.Format(_T("flag=%d,interphone=%s,name=%s"), m_pdbInfo[i].nFlag, m_pdbInfo[i].buddyData.szInterphone, m_pdbInfo[i].buddyData.szName);
for(int j = 0; j < MAX_GROUP_DEPTH; j++)
{
strTemp.Format(_T(",group%d=%s"), j + 1, m_pdbInfo[i].groupData[j].szName);
str += strTemp;
}
str += _T("\r\n");
try
{
#ifdef _UNICODE
USES_CONVERSION;
szBuff = W2A(str);
#else
szBuff = (LPTSTR)(LPCTSTR)str;
#endif
file.Write(szBuff, strlen(szBuff));
}
catch(CException* e)
{
file.Close();
e->Delete();
return FALSE;
}
}
}
catch (CException* e)
{
e->Delete();
return FALSE;
}
file.Close();