본문 바로가기

김탱 개발자/윈도우프로그래밍

CFile 클래스사용 csv파일로 저장 (유니코드)


저장


CFile file;

  

      CString str,str2;


USHORT nShort = 0xfeff;

str2.Format(L"%s\t%s\t%s\t%s\t%s\n",m_List1.GetItemText(0,0),m_List1.GetItemText(0,1),m_List1.GetItemText(0,2)

,m_List1.GetItemText(0,3),m_List1.GetItemText(0,4));


str.Format(L"제품\t단가\t테스트1\t테스트2\t테스트3\n");


if(file.Open(L"test.csv",CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))

{


file.Write(&nShort,2);

file.Write(str, str.GetLength()*2);

file.Write(str2,str2.GetLength()*2);

file.Close();

}

else

{

AfxMessageBox(_T("error"));

}

 

쓰기 (미완성)


CFile file;

      //CString str;


if(file.Open(L"test.csv",CFile::modeRead))

{

CString str,str2;

CString strtmp;

int start=0,end=0;

char Buf[4096] = {0,};

char *Buftmp=NULL;

int index=0;

file.Read(Buf,4096*sizeof(char));

str.Format(L"%s\n",Buf);

AfxMessageBox(str);


index = str.Find('\t');

str2.Format(L"%d\n",index);

AfxMessageBox(str2);


strtmp = str.Left(index);

AfxMessageBox(strtmp);


file.SeekToBegin();

file.Seek(3,CFile::begin);

file.Read(Buftmp,sizeof(char));

str2.Format(L"%s\n",Buftmp);

AfxMessageBox(str2);

//file.Read(Buf,4096*sizeof(char));

//str.Format(L"%s\n",Buf);

//AfxMessageBox(str);


file.Close();

}

else

{

AfxMessageBox(_T("error"));

}


//AfxMessageBox((CString)buffer);

 

'김탱 개발자 > 윈도우프로그래밍' 카테고리의 다른 글

사각영역 잘라내기 (Image Crop)  (0) 2016.02.23
VB6.0 호환 DLL 제작  (0) 2016.02.22
spreadsheet activex control  (0) 2015.11.30
컴파일 옵션 (/MT /MD 등등)  (0) 2015.11.30
DLL 제작  (0) 2015.11.30