DrawingProcess
드프 DrawingProcess
DrawingProcess
전체 방문자
오늘
어제
«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
  • 분류 전체보기 (964)
    • Profile & Branding (22)
      • Career (15)
    • IT Trends (254)
      • Conference, Faire (Experien.. (31)
      • News (187)
      • Youtube (19)
      • TED (8)
      • Web Page (2)
      • IT: Etc... (6)
    • Contents (97)
      • Book (66)
      • Lecture (31)
    • Project Process (94)
      • Ideation (0)
      • Study Report (34)
      • Challenge & Award (22)
      • 1Day1Process (5)
      • Making (5)
      • KRC-FTC (Team TC(5031, 5048.. (10)
      • GCP (GlobalCitizenProject) (15)
    • Study: ComputerScience(CS) (72)
      • CS: Basic (9)
      • CS: Database(SQL) (5)
      • CS: Network (14)
      • CS: OperatingSystem (3)
      • CS: Linux (39)
      • CS: Etc... (2)
    • Study: Software(SW) (95)
      • SW: Language (29)
      • SW: Algorithms (1)
      • SW: DataStructure & DesignP.. (1)
      • SW: Opensource (15)
      • SW: Error Bug Fix (43)
      • SW: Etc... (6)
    • Study: Artificial Intellige.. (149)
      • AI: Research (1)
      • AI: 2D Vision(Det, Seg, Tra.. (35)
      • AI: 3D Vision (70)
      • AI: MultiModal (3)
      • AI: SLAM (0)
      • AI: Light Weight(LW) (3)
      • AI: Data Pipeline (7)
      • AI: Machine Learning(ML) (1)
    • Study: Robotics(Robot) (33)
      • Robot: ROS(Robot Operating .. (9)
      • Robot: Positioning (8)
      • Robot: Planning & Control (7)
    • Study: DeveloperTools(DevTo.. (83)
      • DevTool: Git (12)
      • DevTool: CMake (13)
      • DevTool: NoSQL(Elastic, Mon.. (25)
      • DevTool: Container (17)
      • DevTool: IDE (11)
      • DevTool: CloudComputing (4)
    • 인생을 살면서 (64)
      • 나의 취미들 (7)
      • 나의 생각들 (42)
      • 여행을 떠나자~ (10)
      • 분기별 회고 (5)

개발자 명언

“ 매주 목요일마다 당신이 항상 하던대로 신발끈을 묶으면 신발이 폭발한다고 생각해보라.
컴퓨터를 사용할 때는 이런 일이 항상 일어나는데도 아무도 불평할 생각을 안 한다. ”

- Jef Raskin

맥의 아버지 - 애플컴퓨터의 매킨토시 프로젝트를 주도

인기 글

최근 글

최근 댓글

티스토리

hELLO · Designed By 정상우.
DrawingProcess

드프 DrawingProcess

Study: Software(SW)/SW: Error Bug Fix

[Error Fix] C++ 한글 깨짐 해결 - UTF8 <-> ANSI 문자셋 변환

2020. 6. 23. 09:38
반응형

[C++] 한글 깨짐 해결

모니터 출력 한글 깨짐 : UTF8ToANSI 메소드로 해결

LPCWSTR 에러 : 프로젝트 설정

 

1) 참고

이 문제 해결을 위해 구글링하고 참고했던 내용들은 아래 페이지들에 기록.

[C++] UTF8 <-> ANSI 문자셋 변환 http://blog.daum.net/andro_java/797

[C++] string <-> char* 형변환 http://blog.daum.net/andro_java/795

[C++] "CHAR*" 형식의 인수가 "LPCWSTR" 형식의 매개변수와 호환되지 않습니다. http://blog.daum.net/andro_java/796

[C++] 동적 메모리 할당 - new/delete, new[]/delete[] http://blog.daum.net/andro_java/794

C++에서 stdafx.h/stdafx.cpp - precompiled header http://blog.daum.net/andro_java/793

 

2) 샘플 소스

#include "stdafx.h"

#include <iostream>

#include <string>

#include <fstream>

#include <WTypes.h >

#include <oleauto.h>

using namespace std;



char* UTF8ToANSI(const char *pszCode)

{

	BSTR    bstrWide;

	char*   pszAnsi;

	int     nLength;



	nLength = MultiByteToWideChar(CP_UTF8, 0, pszCode, lstrlen(pszCode) + 1, NULL, NULL);

	bstrWide = SysAllocStringLen(NULL, nLength);



	MultiByteToWideChar(CP_UTF8, 0, pszCode, lstrlen(pszCode) + 1, bstrWide, nLength);



	nLength = WideCharToMultiByte(CP_ACP, 0, bstrWide, -1, NULL, 0, NULL, NULL);

	pszAnsi = new char[nLength];



	WideCharToMultiByte(CP_ACP, 0, bstrWide, -1, pszAnsi, nLength, NULL, NULL);

	SysFreeString(bstrWide);



	return pszAnsi;

}



int main()

{

	ifstream in("D:\\yoil.txt"); // 파일 읽기 준비



	string buff;

	if (in.is_open()) {

		while (getline(in, buff)) { // 파일을 처음부터 끝까지 한줄씩 (마지막 \n 은 자동으로 제거됨) 읽음.

			cout << UTF8ToANSI(buff.c_str()) << endl;

		}

	}

	else {

		cout << "파일을 찾을 수 없습니다!" << endl;

	}



	return 0;

}

 

3) 파일 쓰기

파일을 쓰는 프로젝트에서는 다음 페지에 소개한 ANSIToUTF8 메소드를 활용할 필요가 있을 것이다.

[C++] UTF8 <-> ANSI 문자셋 변환 http://blog.daum.net/andro_java/797

반응형
저작자표시 비영리 변경금지

'Study: Software(SW) > SW: Error Bug Fix' 카테고리의 다른 글

[Error fix] userdel: user sjchoi is currently used by process 14356  (0) 2022.08.05
[Error Fix] invalid new-expression of abstract class type (feat. 추상 클래스)  (0) 2022.07.11
[Error Fix] CMake: undefined reference to 'BIO_write'  (0) 2022.07.07
[Error Fix] Ubuntu 18.04.04 해상도 변경 안 됨(feat 하나로 고정되어 있는 현상 해결)  (0) 2022.06.01
[Trouble Shooting] Git Authentication Failed 사용자 인증 문제 해결  (0) 2022.04.17
    'Study: Software(SW)/SW: Error Bug Fix' 카테고리의 다른 글
    • [Error Fix] invalid new-expression of abstract class type (feat. 추상 클래스)
    • [Error Fix] CMake: undefined reference to 'BIO_write'
    • [Error Fix] Ubuntu 18.04.04 해상도 변경 안 됨(feat 하나로 고정되어 있는 현상 해결)
    • [Trouble Shooting] Git Authentication Failed 사용자 인증 문제 해결
    DrawingProcess
    DrawingProcess
    과정을 그리자!

    티스토리툴바