Post

숫자의 단위를 표시하는 클래스

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
// numstring.h: interface for the numstring class.
//
//////////////////////////////////////////////////////////////////////


#if !defined(AFX_NUMSTRING_H__048C9920_CE10_44AE_A84E_75D2240FCE35__INCLUDED_)
#define AFX_NUMSTRING_H__048C9920_CE10_44AE_A84E_75D2240FCE35__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "isstring.h"

class numstring : public isstring
{
public:
    void operator =(const char* psz);
    numstring(const char* psz);
    virtual ~numstring();
};

#endif // !defined(AFX_NUMSTRING_H__048C9920_CE10_44AE_A84E_75D2240FCE35__INCLUDED_)

 
// numstring.cpp: implementation of the numstring class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <assert.h>
#include "numstring.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
numstring::numstring(const char* psz)
{
    (*this).operator =(psz);
}

numstring::~numstring()
{
}

void numstring::operator =(const char* psz)
{

    string numstr(psz);

    string integer(numstr);
    string::size_type at = numstr.find_first_of(".");
    if(string::npos == at) at = numstr.size();
    while(at > 3)
    {
        numstr.insert(at - 3 , ",");
        at -= 3;
    }
    assign(numstr);
}