c++ 파일 입출력 한글깨짐문제

kunshim의 이미지

텍스트 파일을 열어 20자씩 분류하여 엔터쳐주는 걸 만들고 있는데요 다 하면 새롭게 생성된 것이 한글이 깨져서 나오네요... 어떻게 해야하나요?

#include <iostream> 
using namespace std;
#include <fstream> 
#include <string> 
#include <Windows.h> 
#include <WTypes.h > 
#include <oleauto.h> 
void main()
{
	string ok;//y와 비교시킬것 
	char ch;
	int line = 0;
	system("cls");
	cout << "\n단계 1 먼저 텍스트 파일을 다음의 위치에 집어넣어 주세요." << endl << "위치 : 로컬디스크 C 에서 text to lrc 라는 폴더를 만들고 안에 텍스트 파일을 넣어주세요." << endl << "(단, 텍스트파일의 이름도 text to lrc로 해주세요";
	ifstream fileopen;//파일 출력모드 
	Sleep(500);
loop1:
	cout << "\n텍스트 파일을 집어넣으셨으면 y를 눌러주세요. 다음 단계가 실행됩니다.\n";
	fileopen.open("C:\\text to lrc\\text to lrc.txt", ios::binary);//파일 읽기 모드로 파일 열기 
	getline(cin, ok);
	if (ok == "y")
	{
		if (fileopen.is_open())//파일이 있을 시 
		{
			cout << "파일이 있는 것이 확인되었습니다. 다음으로 넘어값니다\n";
		}
		else//파일이 없을 시 
		{
			cout << "파일이 확인되지 않았습니다. 이전 단계로 돌아값니다. 혹시 파일 확장자가 txt 파일의 이름이 text to lrc인지 확인해주세요\n";
			Sleep(300);
			system("cls");
			goto loop1;
		}
	}
	cout << "\n단계 2 ." << endl;
	ofstream filewrite;
	filewrite.open("C:\\text to lrc\\가사파일.txt");
	while (fileopen.get(ch))
	{
		line++;
		if (ch == ' ')//공백무시 
		{
		}
		else
			filewrite << ch;//파일을 가사파일에 쓴다. 
		if (line % 20 == 0)
		{
			filewrite << "\n";
		}
	}
	fileopen.close();//파일 닫기 
	filewrite.close();//파일 닫기 
	cout << "가사 변환 작업 완료\n" << endl;
	cout << "총 글자수:" << line << endl;
	cout << "가사파일(.lrc)을 음악 이름에 맞추어 넣어 주시면 됩니다.\n" << endl;
	system("pause");
}

코드 올려보겠습니다.. 이게 가사파일 만들어 주는 거라서...
익명 사용자의 이미지

대충 보면 코드에 딱히 문제는 없어 보이네요.
뭐.. 원하는대로 동작은 안하겠지만 문자가 깨질 이유는 없어 보이니까요.

원인은 파일의 문자셋일듯 싶네요.
혹시라도 가사 텍스트 파일의 문자셋이 유니코드나 UTF등이 아닌지 확인해 보십시오.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.