다른 폰트를 물색하던중에 괜찮다고 소문난 Dina 폰트를 사용하기로 했다.
처음엔 좀 어색했는데 쓰면 쓸수록 좋다고 할까.. 암튼 맘에드는 폰트다.

http://dblab.co.kr/entry/소스코드를-html로-변환하기CC -_-..
블로그에 소스를 붙여 넣을때 일일이 색을 넣어주는게 매우 귀찮아던고로 HTML로 변환 해주는게 있지 않을까 하
고 이리저리 뒤져보던 차에 하나 찾은게 src-highlite라는 일종의 리눅스(GNU)쪽 프로그램을 발견했다. 최신버젼
은 윈도우를 지원하지 않는것 같은데 -_-..사이트가 죄다 영어니 ...
http://www.gnu.org/software/src-highlite/
src-highlite-2.1.2 사용하기
Cutomize에 TOOL탭에서 외부도구를 추가 해주는 방식
Command C:\Program Files\GnuWin32\bin\source-highlight.exe // 실행파일의 경로
Arguments에는 -o STDOUT -s cpp -f html --data-dir="C:\Program Files\GnuWin32\share\source-highlight" --line-number-ref "$(FilePath)"
Initial directory에는 $(FileDir) 이거 안되면 $(CurDir)
Use Output Window 체크 src-highlite-2.1.2
default.style는 스타일시트 비슷한것 같다. 이건 share폴더에 복사. gnu-소스하이라이트-guntn.zip
연산자 |
종류 |
결합성 |
우선순위 |
() [] . -> |
최우선연산자 |
좌->우 |
높다 |
! ~ - * & sizeof ++ -- cast |
단항연산자 |
우->좌 |
|
* / % + -
<< >>
< <= > >= != ==
&& || & | ^ |
이항연산자 |
좌->우 |
|
?: |
삼항연산자 |
우->좌 |
|
= += -= *= /= %= <<= >>= &= |= ^= |
대입연산자 |
우->좌 |
|
, |
순차연산자 |
좌->우 |
낮다 |
출처 : http://blog.naver.com/comsik76/30005559569
컴파일시 에러 날(?) 곳을 찾아보아요.(문법적 오류 or 논리적 오류)
// composite.h
#include <list>
#include <memory>
// Composite 패턴을 구현하도록 하는 클래스
template <typename Type, typename Pointer>
class xListComposite : public std::list<Pointer>
{
public :
// 생성자
xListComposite();
// 소멸자
~xListComposite();
// 부모 composite를 설정한다.
inline void setParent(const xListComposite* parent);
// 부모 composite를 반환한다.
inline xListComposite* getParent();
// 자식을 추가한다.
void insertChild(Type* child);
// 자식들을 순환 호출한다.
template <typename Function>
void order(Function& func);
// 자식들을 순환으로 찾는다.
template <typename Function>
Type* find(Function& func);
xListComposite* parent_;
};
// 생성자
template <typename Type, typename Pointer>
xListComposite<Type, Pointer>::xListComposite()
{
}
// 소멸자
template <typename Type, typename Pointer>
xListComposite<Type, Pointer>::~xListComposite()
{
}
// 부모 composite를 설정한다.
template <typename Type, typename Pointer>
void xListComposite<Type, Pointer>::setParent(const xListComposite* parent)
{
parent_ = parent;
}
// 부모 composite를 반환한다.
template <typename Type, typename Pointer>
xListComposite<Type, Pointer>* xListComposite<Type, Pointer>::getParent()
{
return parent_;
}
// 자식을 추가한다.
template <typename Type, typename Pointer>
void xListComposite<Type, Pointer>::insertChild(Type* child)
{
Pointer ptr(child);
ptr->setParent(this);
push_back(ptr);
}
// 자식들을 순환 호출한다.
template <typename Type, typename Pointer, typename Function>
void xListComposite<Type, Pointer, Function>::order(Function& func)
{
func(this);
for (iterator i = begin(); i != end(); i ++)
i->order(func);
}
// 자식들을 순환으로 찾는다.
template <typename Type, typename Pointer, typename Function>
Type* xListComposite<Type, Pointer, Function>::find(Function& func)
{
if (func(this))
return this;
for (iterator i = begin(); i != end(); i ++)
if (i->find(func))
return i->get();
}
/// leaf.h
#include "composite.h"
// composite를 이용하는 노드를 생성한다.
class xLeaf : public xListComposite<xLeaf>
{
public :
xLeaf(const char* name)
{
name_ = new char [128];
strcpy(name_, name);
}
~xLeaf()
{
delete name_;
}
char* name_;
}; // xLeaf
/// program.cpp
#include "leaf.h"
struct Ldisplay
{
void operator () (xLeaf* leaf)
{
std::cout << leaf->name_;
}
};
struct Lfind
{
Lfind(char* find)
{
strcpy(find_, find);
}
bool operator () (xLeaf* leaf)
{
return strcmp(leaf->name_, find_) == 0;
}
char find_[128];
};
void main()
{
xLeaf root("과일");
root.insertChild(new xLeaf("사과"));
root.insertChild(new xLeaf("바나나"));
root.insertChild(new xLeaf("복숭아"));
root.insertChild(new xLeaf("배"));
xLeaf* leaf = root.find(Lfind("사과"));
leaf->insertChild(new xLeaf("부사"));
leaf->insertChild(new xLeaf("국광"));
root.order(Ldisplay());
}
// 버그 수정및 결과 예측
if(input == 5)
num = 5;
else
num = 0;
이런 패턴이 있다면 더 줄여 보고자 하는 욕심을 가지는 것이 좋다.
삼항조건연산자는 그저 이게 맞다면 앞에꺼 리턴 이런 생각을 가지기 쉬운데 더 응용해보자.
num = (input == 5) ? 5:0; 로 위에 코드를 대폭 줄일 수 있고 또,
(input == 5) ? ((output == 'a') ? 5 : 0) : 0; 같은 코드를 사용해서 if문을 중첩한 효과를 낼수
있다.
0과 다른수를 리턴하고자 할때 아주 간단하게 표현 가능한데
num = (input == 5) * 5;
생각해보면 간단하지만 참일때 1 , 거짓일때 0을 리턴한다는 것을 잘 활용한게 아닌가 싶다.
여러코드를 코드를 보다보면 이렇게도 응용을 할수 있구나라는 생각이든다.
과연 그 코드를 모르는 상태에서 이러한 코드를 생성할수 있을까...
/*10진수를 16진수로 출력하는 프로그램*/
#include <stdio.h>
void main()
{
int input;
int low, hi;
while(1)
{
printf("0~255사이의 수를 입력하시오: ");
scanf("%d", &input);
hi = input >> 4;
low = input & 0xf;
printf("입력한 수의 16진 표기 = %c%c\n", hi+'0'+(hi > 9)*7, low+'0'+(low > 9)*7);
}
}
10진에서 16진수를 구하기 위해 상위비트는 비트연산자를 통해 구하고
하위비트는 논리연산자로 마스크(?)를 만들어서 변수에 저장 시켰다.
그리고 나서 이를 16진수로 바꾸기 위해서 0의 아스키코드값 48과 더하면 9를 초과하는지의
여부를 알 수 있다. (hi >9)가 참이면 1 아니면 0을 리턴하는 것을 응용하여 9를 초과 했다면
아스키코드값이 대문자 A가 부터 표현하기 위해 7을 더해준다. (브라보!)
scanf("%f", &f);
printf("%f\n", f);
float형 변수 f에 임의의 수를 입력했을 때 컴파일러가 문제인지 몰라도 12.2를 입력하면
12.200000 이 출력 되는데
printf("%d\n", i=(int)(f * 100));
printf("i = %d\n", i%100);
이런 코드를 통해 소수점 이하 두자리를 구하려고 하니깐 19가 나온다..-_-;;
초난강 모드로 빠져 든다.
float형 변수는 다루기 힘든 건가..
벌써부터 어깨가 뻐근한게 죽을 맛이다. 몸이 찌뿌둥 하다고 해야하나.. 앉아 있으면 시간이
물 흐르듯이 지나가서 하루가 이리 빨리 가나 싶다.
ch=getch();
if (ch == 0xE0 || ch == 0) {
ch=getch();
}
getch()함수로 키보드로 입력되는 값을 ch 변수에 저장하고자 할때 아스키코드값 이외의
값을 받게 되면 0xE0(224)나 0 값을 리턴하게 되는데 이때 다시한번 getch()함수로 표준입력
을 변수에 대입시키게 되면 스캔코드를 얻을 수 있게 된다.
콘솔창내에서 커서를 이동시키고자 할 때 방향키를 누르면 그때 발생되는 스캔코드를 읽어
드려서 커서의 위치를 변경할때 쓰인다.