XLNT Livrary 첨부 (debug, release) 같이 있음

VisualStudio 2017 x64 XLNT Library.zip
2.31MB

 

모든 구성으로 해야 debug, release 같이 

 

dll 위치 설정

헤더 파일 경로 설정

 

lib 파일 설정

 - debug

 - release

링커 입력에 추가하기 싫으면 상위 헤더 파일에 밑에 코드 추가 (위의 설정과 같은 역할)

#include <xlnt/xlnt.hpp>
#ifdef _DEBUG 
#	pragma comment (lib , "../ExternalLib/lib/xlntd.lib")
#else
#	pragma comment (lib , "../ExternalLib/lib/xlnt.lib")
#endif

예제 1 (MFC 사용으로 CString 으로 값 받아옴)

// xlsx 파일을 열고 워크시트에 액세스 한다.
xlnt::workbook wb;
wb.load("file.xlsx");
auto ws = wb.active_sheet();

//워크시트에서 데이터를 읽습니다.
for (auto row : ws.rows(false))
{
    for (auto cell : row)
    {
        std::cout << cell.to_string() << " ";
    }
    std::cout << std::endl;
}

// double 형으로 형변환

for (auto row : ws.rows(false))
{
    for (auto cell : row)
    {
        if (cell.data_type() == xlnt::cell::type::numeric)
        {
            auto value = cell.value<double>();
            std::cout << value << " ";
        }
        else
        {
            std::cout << cell.to_string() << " ";
        }
    }
    std::cout << std::endl;
}

 

출처 : https://luckygg.tistory.com/235#google_vignette

Posted by pi92
CString ToStringFormat(const char* lpstrFormat, ...)
{
	va_list list;
	char strText[2000] = { 0 };

	va_start(list, lpstrFormat);
	vsprintf_s(strText, lpstrFormat, list);
	va_end(list);

	CString str(strText);
	return str;
}

사용 방법

ToStringFormat("%d + %d = %d", 1, 2, 3);

return "1 + 2 = 3"

 

 

Posted by pi92

2021. 10. 19. 13:15 자기개발/C++

C++ - interface

인터페이스는 특정 기능을 구현할 것을 약속한 추상 형식을 말합니다.

 

 개발자들 사이에 인터페이스 이름은 I로 시작하고 I뒤에 약속하는 기능을 붙이고 있어요. 따라서 Play 기능을 약속하는 인터페이스는 IPlay라고 명명합니다. 물론 인터페이스는 여러 개의 기능을 약속할 수 있겠죠. 이 때도 대표하는 기능을 이름에 포함하세요.

물론 인터페이스를 기반으로 파생한 형식은 약속한 기능을 재정의하여 구체적으로 구현하여야 개체를 생성할 수 있습니다. 다음은 인터페이스 IPlay에서 파생한 Man 클래스에서 약속한 기능 Play를 재정의하여 사용하는 예제 코드입니다.                                                                              

 

//인터페이스 정의를 통해 같은 방법으로 다양한 형식 개체 사용
//Program.cpp
#include <iostream>
#include <string>
using namespace std;
 
#define interface struct
interface IPlay 
{
    virtual void Play()=0;
};
 
class Man:public IPlay
{
    string name;
public:
    Man(string name)
    {
        this->name = name;
    }
    virtual void Play()
    {
        cout<<name<<" 연주하다."<<endl;
    }    
};
 
void Concert(IPlay *iplay)
{
    iplay->Play();
}
int main()
{
    Man *man = new Man("홍길동");
    Concert(man);
    delete man;
    return 0;
}

실행결과

 

홍길동 연주하다.

 

출처 : https://ehpub.co.kr/

Posted by pi92

 기본적으로 함수를 호출 할 때에는 오버헤드 패널티가 발생합니다. 하지만 inline 함수는 이러한 오버헤드를 줄이고 C++의 실행 속도 개선을 위해 등장 했습니다. 비슷한 기능으로는 C언어에서 매크로 함수가 있습니다. 

 

(+)매크로 함수는 전처리기에 의해서 처리되지만, inline 함수는 컴파일러에 의해 처리가 됩니다.

 

매크로 함수의 예

#include <iostream>
#define DOUBLE(x) ((x)*(x))
using namespace std;

int main(void)
{
	cout << DOUBLE(2) << endl;
    return 0;
}

실행시 

#include <iostream>
#define DOUBLE(x) ((x)*(x))
using namespace std;

int main(void)
{
	cout << ((2)*(2)) << endl;
    return 0;
}

변경되어 나옵니다.

 

 

inline 함수 예

#include<iostream>

inline int Double(int a){    return a * a;}

int main(void){
    int num;
    num = Double(5);
    return 0;
}

실행시

#include<iostream>

inline int Double(int a){    return a * a;}

int main(void){
    int num;
    num = 5*5;
    return 0;
}

변경되어 나옵니다.

 

하지만 보시는것처럼 inline 함수는 인자가 정해져 있어서 위의 식에서 인자가 int형이므로 실수를 넣었을 시 원하는 값이 나오지 않을 수 있습니다. 하지만 템플릿을 사용하여 정수나 실수형을 모두 커버할 수 있는 인라인 함수를 만들수 있습니다.

 

template을 적용한 inline 함수 예

#include <iostream>

template <typename T>
inline T Double(T a){ return a*a; }

int main(void){
    int num;
    num = Double(2.5);
    return 0;
}
Posted by pi92
#define _AFXDLL 
#include <afxwin.h>
#include <atlimage.h>
#include <iostream>
using namespace std;

void point_swat(int* a, int* b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

int  main(void)
{

	int w = 120;
	int h = 100;
	//Make Gray image(1BYTE)
	LPBYTE grayBits = nullptr;
	grayBits = new BYTE[w * h];

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			grayBits[i*w + j] = 255 - (double)255 * j / (w - 1);
		}
	}

	//gray를 컬러 이미지(3BYTE)로
	LPBYTE colorBits = nullptr;
	colorBits = new BYTE[w * h * 3];

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			colorBits[i * 3 * w + 3 * j] = grayBits[i*w + j];
			colorBits[i * 3 * w + 3 * j + 1] = grayBits[i*w + j];
			colorBits[i * 3 * w + 3 * j + 2] = grayBits[i*w + j];
		}
	}

	//컬러로 옮겨준 후 메모리 삭제
	delete[] grayBits;
	grayBits = nullptr;


	//colorBits 에 빨간색 사각형 넣기
	int start_x = 30, start_y = 30, end_x = 66, end_y = 60;

	if (start_x < 0 || start_x > w || end_x < 0 || end_x > w || start_y < 0 || start_y > h || end_y < 0 || end_y > h)
	{
		cout << " 사각형 영역이 잘못 그려 졌습니다." << endl;
		return 0;
	}

	if (start_x > end_x) point_swat(&start_x, &end_x);
	if (start_y > end_y) point_swat(&start_y, &end_y);


	//사각형 채워서 그리기
	//for (int i = start_y; i < end_y+1; i++)
	//{
	//	for (int j = start_x; j < end_x+1; j++)
	//	{
	//		colorBits[i * w * 3 + 3*j] = 0;
	//		colorBits[i * w * 3 + 3*j + 1] = 0;
	//		colorBits[i * w * 3 + 3*j + 2] = 255;
	//	}
	//}


	//사각형 세로 그리기
	for (int i = start_y; i < end_y + 1; i++)
	{
		colorBits[i * w * 3 + 3 * start_x] = 0;
		colorBits[i * w * 3 + 3 * start_x + 1] = 0;
		colorBits[i * w * 3 + 3 * start_x + 2] = 255;

		colorBits[i * w * 3 + 3 * end_x] = 0;
		colorBits[i * w * 3 + 3 * end_x + 1] = 0;
		colorBits[i * w * 3 + 3 * end_x + 2] = 255;
	}

	//사각형 가로 그리기
	for (int j = start_x; j < end_x + 1; j++)
	{
		colorBits[start_y * w * 3 + 3 * j] = 0;
		colorBits[start_y * w * 3 + 3 * j + 1] = 0;
		colorBits[start_y * w * 3 + 3 * j + 2] = 255;

		colorBits[end_y * w * 3 + 3 * j] = 0;
		colorBits[end_y * w * 3 + 3 * j + 1] = 0;
		colorBits[end_y * w * 3 + 3 * j + 2] = 255;
	}


	//이미지 저장할 CImage 변수 생성
	CImage image;
	image.Create(w, h, 24);
	RGBQUAD rgbQuad[256];
	for (int i = 0; i < 256; i++) {
		rgbQuad[i] = { BYTE(i),BYTE(i),BYTE(i),0 };
	}
	//image.SetColorTable(0, 255, rgbQuad);


	//image에 colorBits 데이터값 넣기
	LPBYTE m_pBits = (LPBYTE)image.GetBits();
	for (int i = 0; i < h; i++) {
		LPBYTE pRow = m_pBits + (i*image.GetPitch());
		memcpy(pRow, colorBits + (i*w * 3), w * 3);
	}


	CreateDirectory(_T("save"), NULL);
	image.Save(_T("save/temp.bmp"));
	image.Destroy();

	//colorBits 해제
	delete[] colorBits;
	colorBits = nullptr;

	_CrtDumpMemoryLeaks();

	return 0;
}

 

Posted by pi92
#define _AFXDLL 
#include <afxwin.h>
#include <atlimage.h>

int  main(void)
{
	int w = 50;
	int h = 30;
	LPBYTE pBits = nullptr;
	pBits = new BYTE[w * h];

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			pBits[i*w + j] = j;
		}
	}

	CImage image;
	image.Create(w,h,8);
	RGBQUAD rgbQuad[256];
	for (int i = 0; i < 256; i++) {
		rgbQuad[i] = { BYTE(i),BYTE(i),BYTE(i),0 };
	}
	image.SetColorTable(0, 255, rgbQuad);


	LPBYTE m_pBits = (LPBYTE)image.GetBits();
	for (int i = 0; i < h; i++) {
		LPBYTE pRow = m_pBits + (i*image.GetPitch());
		memcpy(pRow, pBits + (i*w), w);
	}

	image.Save(_T("temp1.bmp"));
	image.Destroy();

	delete[] pBits;
	pBits = nullptr;


	_CrtDumpMemoryLeaks();

	return 0;
}
Posted by pi92
#include <iostream>
using namespace std;
#pragma warning(disable:4996)

typedef struct Node
{
	char m_strName[256];   ///< 이름
	int  m_nAge;         ///< 나이 
	struct Node* m_pNext;   ///< Next Node Pointer

}NODE, *LPNODE;

void   InsertNode(struct Node** pHead, const char* pStrName, int nAge);
void   DisplayNode(struct Node* pHead);
void   DeleteNode(struct Node** node, int nAge);

int main()
{
	LPNODE   pHead = nullptr;

	//===============================================================================
	//  pHead 를 함수 인자로 넘겨서 Single Linked List를 구현할 것 
	//  ... 으로 되어있는 부분 채워넣을 것 
	//===============================================================================

	InsertNode(&pHead, "aaa", 1);
	InsertNode(&pHead, "bbb", 2);
	InsertNode(&pHead, "ccc", 3);
	InsertNode(&pHead, "ddd", 4);
	InsertNode(&pHead, "eee", 5);

	DisplayNode(pHead);
	// (aaa, 1) -> (bbb, 2) -> (ccc, 3) -> (ddd, 4) -> (eee, 5)
	cout << endl;

	DeleteNode(&pHead, 1);
	DeleteNode(&pHead, 3);
	DeleteNode(&pHead, 5);

	DisplayNode(pHead);
	////(bbb, 2) -> (ddd, 4)

	system("pause");

	return 0;
}

void   InsertNode(struct Node** Head, const char* pStrName, int nAge)
{
	struct Node* newNode = new Node;
	struct Node* prev = *Head;

	newNode->m_nAge = nAge;
	strcpy(newNode->m_strName, pStrName);
	newNode->m_pNext = NULL;

	//순차적으로 추가 1->2->3->4
	//if (*Head == NULL)
	//{
	//	*Head = newNode;
	//	return;
	//}
	//while (prev->m_pNext != NULL)
	//	prev = prev->m_pNext;
	//prev->m_pNext = newNode;



	//역순으로 추가 5->4->3->2->1
	if (*Head == NULL)
	{
		*Head = newNode;
		return;
	}
	else
	{
		newNode->m_pNext = prev;
		*Head = newNode;
		return;
	}

}

void   DisplayNode(struct Node* node)
{
	while (node != NULL)
	{
		cout << "(" << node->m_strName << "," << node->m_nAge << ") ";
		node = node->m_pNext;
		if (node != NULL)
			cout << "->";
	}cout << endl;
}

void   DeleteNode(struct Node** node, int nAge)
{
	struct Node* temp;
	struct Node* prev;

	temp = *node;
	prev = temp;

	while (temp != NULL)
	{
		if (temp->m_nAge == nAge)
		{
			if (temp == *node) {
				*node = (*node)->m_pNext;
				return;
			}
			prev->m_pNext = temp->m_pNext;
			delete temp;
			temp = nullptr;
			return;
		}

		prev = temp;
		temp = temp->m_pNext;
	}

	if (temp == NULL)
	{
		cout << "입력 값이 없습니다." << endl;
	}

}
Posted by pi92
이전버튼 1 이전버튼

블로그 이미지
pi92

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
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

최근에 올라온 글

최근에 달린 댓글

글 보관함