opendir이 반환하는 포인터 객체의 멤버인 d_name으로 한글 파일을 표시하려면 어떻게 해야 하나요?

dltkddyd의 이미지

#include <dirent.h>
#include <iostream>
using namespace std;
 
int main() {
  DIR* dp=opendir("/home/elephant/Documents");
  dirent* filelist;
  while(  (filelist=readdir(dp)!=NULL  ) {
    wcout<<filelist->d_name<<endl;    
  }
}

위와 같이 해서 Documents 폴더의 파일들의 이름을 나열합니다. 영어로 된 파일을 제대로 표시가 되는데, 한글로 된 파일은 제대로 표시가 돼지 않습니다. 그렇다고 한글로 된 파일이 인식되지 않는 것은 아닌 것으로 보입니다. 한글로 된 파일을 open 함수로 열면 제대로 열리기 때문입니다. 한글 파일이 제대로 표기가 안 될 뿐, 파일은 제대로 열리고 닫힙니다. 한글 파일 표기가 제대로 되게하려면 어떻게 해야 할까요?

shint의 이미지

opendir
readdir
wout
으로 네이버에 찾아보니 다양한 답변이 있었습니다.

- 제가 다 떼다 붙여서 정리하고 싶지만. 욕 먹을 거 같아서 ㅡ_ㅡ;;
- 없는 답변으로는 파일 형태였던거 같습니다.

파일을 저장할때. ANSI. UTF8.등에 파일로 저장하는거죠...
파일 자체를 저장하는거라 함수에 locale 변경하는거나 비슷할지도 모릅니다.
하나씩 해보면서 알려드려야 하는데... ㅡ_ㅡ;; 설치할 일이 많네요... iconv같은 변환함수같은 것도 있습니다.

언어에 대한 원리를 알려드려야 하는데...
한글 조합형 C언어'로 검색해보세요. 많이 나오네요.

그리고. 책 사시면. IME 나 완성형 조합형 언어에 대한 내용이 적힌것도 있습니다.

생각보다 내용이 많아서. 한번 보시는게 좋을거 같습니다.

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

chanik의 이미지

wcout은 wchar_t[] 문자열을 기대하는데
dirent->d_name은 그냥 char[] 라서 생기는 일 같은데요.
(char[] 타입에 대개는 UTF-8이나 EUC-KR 문자열을 담고 있을 것입니다)

wcout 말고 그냥 cout에 출력하시는 것이 자연스럽지 않은가요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.