반응형

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <cstdio>
#include <string>
#include <regex>
 
#define print(x) cerr << #x << " is " << x << endl;
 
using namespace std;
 
int sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }
int main()
{
    /*
        이 print 매크로를 이용하면 간단한 디버깅에 용이할 것 같다.
    */
    string crocus = "www.crocus.co.kr";
    print(crocus);
    print(+ 2);
 
    /*
        위의 세문장으로 sum을 아래와 같이도 표현 할 수 있다.
    */
    cout << endl;
    print(sum(12345));
    /*
        [j == 9]의 의미 ::
        " \n"은 하나의 string이다.
        따라서 [0]은 ' '를 의미하고있고 [1]은 '\n'을 의미하고있다.
        따라서 j == 9면 true(1) j != 9면 false(0)이기에
        j가 9일때 " \n"[1]을 호출하게 되는 것이다.
    */
    cout << endl;
    for (int i = 1; i <= 5; i++
        for (int j = 0; j <= 9; j++)
            cout << 10*+ j << " \n"[j == 9];
 
    cout << endl;
    /*
    raw string을 이용한 문자열 처리
    */
    string row_str =
        R"(여기서는 \n같은 것은 이용할 수 없으나
엔터를 치면 자연스럽게 \n효과가 납니다.
즉 R"(~) "을이용하면 스트링이 raw형태로 변하게 됩니다.
)";
 
    cout << row_str << endl;
 
    /*
        #include <regex>
        정규 표현식을 이용 할 수 있다. 
        http://www.cplusplus.com/reference/regex/
    */
    regex email_pattern(R"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)");
    string
        mail_1("kkw564@naver.com"),
        mail_2("crocus");
 
    cout << '\n';
    printf("%s is %s\n", mail_1.c_str(), regex_match(mail_1, email_pattern) ? " valid" : " invalid");
    printf("%s is %s\n", mail_2.c_str(), regex_match(mail_2, email_pattern) ? " valid" : " invalid");
    cout << '\n';
 
    return 0;
}






반응형

'Basic > C++' 카테고리의 다른 글

비트연산을 이용한 Packing / Unpacking  (0) 2019.04.02
16진수를 2진수로 변환  (2) 2018.04.14
setprecision 함수  (0) 2017.02.14
cin, cout의 이용 방법 및 견해  (0) 2016.11.08
stack 표준 템플릿 라이브러리 이용 방법  (0) 2016.08.14