전체 글 725

cygwin/mingw 의 g++ 로 utf-8 한글 처리하기

다음은 utf-8 인코딩으로 저장한 C++ 소스이다. Cygwin의 g++ tkdyd tl, 만일 아래의 소스에서 std::setlocale(LC_ALL, "ko_KR.UTF-8"); 대신 std::locale::global (std::locale ("ko_KR.UTF-8")); 로 하면 캄핑ㄹ은 되지만 실행 시에 Segmentation fault (core dumped) 에러가 난다. * 소스 파일명: testLocale_003.cpp // Filename: testLocale_003.cpp // // Compile: g++ -std=c++11 -o testLocale_003 testLocale_003.cpp // or g++ -std=c++0x -o testLocale_003 testLocale_00..

프로그래밍/C++ 2014.04.10

cygwin/mingw 의 gcc 로 utf-8 한글 처리하기

우선 다음은 ms949 인코딩으로 저장한 C 소스이다. * 소스 파일명: hello.c #include #include int main() { printf("Hello, 안녕하세요?\n"); printf("strlen(\"Hello, 안녕하세요?\\n\") = %d\n", strlen("Hello, 안녕하세요?\n")); return 0; } * 컴파일 > gcc -o hello hello.c * 실행 > hello Hello, 안녕하세요? strlen("Hello, 안녕하세요?\n") = 19 다음은 utf-8 인코딩으로 저장한 C 소스이다. * 소스 파일명: hello2.c #include #include #include #include #define wstrlen wcslen int main() {..

프로그래밍/C 2014.04.02

koTeX 과 verbments 패키지를 이용하여 (한글 문자 포함된) 프로그램 소스를 문서에 표현하기

아래의 소스는 koTeX 2012 이상이면 컴파일되는 TeX 소스이다. TeXworks 에서 XeLaTeX 으로 컴파일하면 에러는 없자만 소스 리스팅 부분이 제대로 반영되지 않는다. 차라리 명령줄애서 --shell-escape 옵션을 주고 xelatex 명령으로 컴파일하는 것이 확실하다. \begin{pyglist}[language=python,encoding=utf8] 처럼 옵션 encoding=utf8 이 있어야 한글이 출력된다, 컴파일하기: 프롬프트> xelatex --shell-escape ex-verbments-01.tex * 파일명: ex-verbments-01.tex \documentclass{article} \usepackage{kotex} \usepackage{verbments} \beg..

프로그래밍/TeX 2014.03.20

koTeX 과 minted 패키지를 이용하여 (한글 문자 포함된) 프로그램 소스를 문서에 표현하기

아래의 소스는 koTeX 2012 이상이면 컴파일되는 TeX 소스이다. TeXworks 에서 XeLaTeX 으로 컴파일하면 -shell-escape 옵션이 필요하다는 에러 메시지가 뜬다. 컴파일하기: 프롬프트> xelatex --shell-escape ex-minted-01.tex * 파일명: ex-minted=01.tex \documentclass[12pt,a4paper]{article} \usepackage{kotex} \usepackage{hyperref} \usepackage{minted} \begin{document} % v\begin{minted}[ruby] \begin{minted}{ruby} =begin Usual operators(평범한 사칙연산자): + addition(덧셈) - sub..

프로그래밍/TeX 2014.03.20

koTeX 과 listings 패키지를 이용하여 (한글 문자 포함된) 프로그램 소스를 문서에 표현하기

아래의 소스는 koTeX 2012 이상이면 컴파일되는 TeX 소스이다. TeXworks 에서 XeLaTeX 으로 컴파일해도 되고, pdfLaTeX 으로 컴파일해도 된다. 한글이 정상적으로 출력되게 하려면, \begin{lstlisting}[frame=single,escapeinside=~~] 처럼 옵션 escapeinside=~~ 을 주고 ~아무개~ 하면 아무개가 출력된다. 만일 옵션 escapeinside=^$ 을 주었다면 ^아무개$ 해야 아무개가 출력된다. * 파일명: ex-listings=03.tex \documentclass{article} \usepackage{kotex} \usepackage[T1]{fontenc} \usepackage{listings} % Include the listings..

프로그래밍/TeX 2014.03.20

Go 1.2 설치 후 에러 메시지(pack: cannot open $WORK\command-line-arguments\_obj\_go_.8) 해결하기

* Go 1.2 내려받기 (윈도우즈 용으로는 zip 파일이든 msi 파일이든 아무거나 내려받아 설치해도 된다.) 아래에서는 32비트 윈도우 XP 용으로 내려받아 테스트하였다. Go 1.2 를 폴더 d:\go12 에 설치하였다. * 테스트에 사용된 예제 파일: hello.go package main import "fmt" func main() { fmt.Printf("hello, world\n") } * Go 1.0.2 를 사용할 때 처럼, 명령(cmd)창을 열고 환경변수 PATH 를 설정한다. 프롬프트> set PATH=d:\go12\bin;%PATH% * go run 멸형으로 hello.go 를 실행한다. 프롬프트> go run hello.go # command-line-arguments pack: c..

프로그래밍/Go 2014.03.02

pyqtgraph 를 이용한 그래프 그리기 예제

* pyqtgraph 내려받기 * 예제 소스 (극곡선 r = 2 cos(3 theta) 그리기) # -*- coding: utf-8 -*- # Filename: testPyQtGraph_03.py # Execute: python testPyQtGraph_03.py from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="Basic plotting examples") win.resize(400, 500) win.setWindowTitle('pyqtgraph example: Plotting') # Enable ant..

Qt 5.2.1 의 Qt Creater 3.0.1 을 이용한 Hello 예제 작성하기

* Qt 5.2.1 내려받기 (아래의 예는 Visual Studio 2010 용을 받아서 설치한 경우이다. Qt Creator 3.0.1 은 자동으로 함께 설치된다,) Qt Creator 를 시작한 후 메뉴에서 File --> New File or Project... 를 택한다. 그리고 New 창에서 다음 그림에서와 같이 Applications --> Qt Quick Application 을 택하고 "Choose..." 버튼을 클릭한다. 이어 나타나는 New Qt qUICK aPPLICATION 창에서 애플리케이션이 생성될 폴더와 이름을 정한다. 원하는 폴더거 없는 경우 그 우측의 "Browse" 버튼을 클릭하여 생성하거나 선택한다. 다음 창에서는 Qt Quick Componenet Set 을 정한다. ..

프로그래밍/C++ 2014.02.28

PySide 를 이용한 UI 예제

** PySide 설치하기 ** QtDesigner 내려받기 ** 윈도우즈 용 git 를 설치하기 * 다음 소스는 http://qt-project.org/wiki/PySideSimplicissimus_Module_2_CloseButton 에서 볼 수 있는 소스이다. #!/usr/bin/env python # quitter.py - provide a button to quit this "program" import sys from PySide.QtGui import QMainWindow, QPushButton, QApplication from ui_quitter import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): def __init__(s..

PyQt4 를 이용한 GUI 예제: 두 자리 수 곱셈 쉽게 하기

전개 공식 (ax + b)(cx + d) = acx^2 + (ad + bc)x + bd 에 기반을 둔 쉬운 곱셉법(일명 카라슈바 곱셈법)이다. 여기서 특히 a == b or a == c or b == d or c == d 인 경우이면 ad + bc = s(c + d) or ad + bc = a(b + d) or ad + bc = b(s + c) or ad + bc = c(a + b) 로 더 쉬운 곱셈 계산이 가능하다. #!/usr/bin/python # -*- coding: utf-8 -*- # Filename: ezMult_02.py # # Execute: python ezMult_02.py # # See: http://zetcode.com/gui/pyqt4/widgets2/ # See: http://..