CString을 file로 제대로 저장하자(MS Visual C++ 2005)
Posted 2009. 8. 31. 15:10
Microsoft VisualStudio 2005 이후 부터는 문자열을 유니코드로 처리한다.
한가지 문제가 있다.
문자열을 파일로 저장할 시, 길이가 맞지 않으며,
파일을 저장하고 열면 글씨가 깨져 나온다.
해결책)
CFile wFile;
CFileException e;
WORD wd = 0xFEFF; //unicode 식별자
CString str = L"안녕하세요";
if(wFile.Open(_T("hello.txt"), CFile::modeCreate | CFile::modeWrite), &e)
{
wFile.Write(&wd,2); //unicode 식별자 파일 처음에 쓰자
wFile.SeekToEnd();
wFile.Write(str, str.GetLength()*sizeof(TCHAR));
wFile.Close();
}
else
{
e.ReportError();
}
CFileException e;
WORD wd = 0xFEFF; //unicode 식별자
CString str = L"안녕하세요";
if(wFile.Open(_T("hello.txt"), CFile::modeCreate | CFile::modeWrite), &e)
{
wFile.Write(&wd,2); //unicode 식별자 파일 처음에 쓰자
wFile.SeekToEnd();
wFile.Write(str, str.GetLength()*sizeof(TCHAR));
wFile.Close();
}
else
{
e.ReportError();
}
★~ CString이랑 유니코드가 만났을 때...
'PC > programming' 카테고리의 다른 글
[tip] eclipse 에디터의 현재 커서가 있는 줄 색깔 바꿔보자 (0) | 2010.01.21 |
---|---|
[tip] eclipse 에디터의 배경색을 바꿔보자 (0) | 2010.01.18 |
CString을 file로 제대로 저장하자(MS Visual C++ 2005) (0) | 2009.08.31 |
ClearCase, 시간으로, label로 가져오기(config spec) (0) | 2008.09.22 |
Source Insight, 한글 제대로 나오게 하기 (0) | 2008.08.28 |
[programming] new IME, just Flick ! (0) | 2008.04.13 |
- Filed under : PC/programming
- Tag : 2005, CString, File, Unicode, Visual C++, Write, 쓰기, 유니코드, 저장
- 0 Comments 0 Trackbacks