#include "fstream"

std::ofstream		fOutDataFile;	// 파일 생성 및 입력
std::ifstream		fInDataFile;	// 파일 읽어 오기

// 파일 생성
{
	// 바이너리 값을 입력 할 수 있도록 생성
	fOutDataFile.open( "DataFile.dat", std::ios_base::binary );

	if ( fOutDataFile.fail() )
	{
		return;
	}
}

// INT형 쓰기
{
	int		nValue;

	fOutDataFile.write( (const char*)nValue, sizeof(nValue) );
}

// String형 쓰기
{
	std::string strValue = "MonsterName";
	int			nSize	 = strValue.size();

	fOutDataFile.write( (const char*)nSize, sizeof(nSize) );
	fOutDataFile.write( strValue.c_str(), nSize );
}

// 파일 읽기
{
	int nOpenMode = std::ios_base::in || std::ios_base::binary;

	fInDataFile.open( "DataFile.dat", nOpenMode );

	if ( fInDataFile.fail() )
	{
		return;
	}
}

// INT형 읽기
{
	int		Value = 0;

	fInDataFile.read( (char*)&Value, sizeof(Value) );
}

// String형 읽기
{
	int			nSize		= 0;	
	char		Buf[512]	= "";
	std::string	strValue	= "";

	fInDataFile.read( (char*)&nSize, sizeof(nSize) );
	fInDataFile.read( Buf, nSize);

	strValue = Buf;
}

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

숫자 타입 String에 담기  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
#include "sstream"

{
	std::string			strString;
	std::ostringstream	ost;
	int					nNumber = 100;

	ost.str("");
	ost << nNumber;

	strString += ost.str();
}

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

파일 입출력 사용법 정리  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
CWinThread*		WinThread = NULL;

// 쓰레드로 처리할 루프
UINT __cdecl ThreadLoop(LPVOID pParam)
{
	BOOL *pbContinue = (BOOL *)pParam;

	while(*pbContinue)
	{
		Sleep(1);
	}

	return 0;
}

// 쓰레드 시작
WinThread = AfxBeginThread(ThreadLoop, this);

// 쓰레드 종료
DWORD nExitCode = NULL ;

GetExitCodeThread( WinThread->m_hThread, &nExitCode ) ;
TerminateThread( WinThread->m_hThread, nExitCode ) ;

'Programming > API' 카테고리의 다른 글

[API] Basic Window  (0) 2010.09.16
Posted by Habentius
:
#include "boost shared_ptr.hpp"

class CEntity
{
private:
	int	m_nEntityType;

public:
	void SetEntiyType(int a_nEntityType)	{ m_nEntityType = a_nEntityType; }
	int  GetEntiyType(void)					{ return m_nEntityType; }

public:
	CEntity(void) {}
	~CEntity(void) {}
};

{
	// 선언 및 동적 할당
	// 스마트 포인터의 경우 선언과 동시에 동적할당을 해 주어야 한다.
	boost::shared_ptr		spEntity(new CEntity);

	// 포인터 처럼 사용 하면 된다.
	spEntity->SetEntiyType( TY_MONSTER );
	int nEntityType		= spEntity->GetEntiyType();

	 // 포인터 얻어 오기
	CEntity* pentity	= spEntity.get();
}

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

파일 입출력 사용법 정리  (0) 2012.11.05
숫자 타입 String에 담기  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
#include 

struct ObjectInfo
{
	int nX;
	int nY;
};

std::map	ObjectMapList;

//	Map 루프
{
	std::map::iterator iter	= ObjectMapList.begin();
	std::map::iterator end		= ObjectMapList.end();

	for ( /**/;	iter != end; ++iter )
	{
		if ( iter == ObjectMapList.end() )
		{
			continue;
		}

		std::string		objectname	= iter->first;
		ObjectInfo		objectinfo  = iter->second;
	}
}

// Map 검색
{
	std::map::iterator iter = ObjectMapList.find("Renderer");

	if ( iter == ObjectMapList.end() )
	{
		return NULL;
	}

	return iter->second;
}

// Map 삽입
{
	std::string		objectname;
	ObjectInfo		objectinfo;

	objectname	  = "Renderer";
	objectinfo.nX = 0;
	objectinfo.nY = 0;

	ObjectMapList.insert( std::pair( objectname, objectinfo ) );
}

// Map 삭제
ObjectMapList.clear();
 
{
    std::map::iterator iter = ObjectMapList.find("Renderer");
 
    if ( iter == ObjectMapList.end() )
    {
        return NULL;
    }
 
    ObjectMapList.erase( iter );
}


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

파일 입출력 사용법 정리  (0) 2012.11.05
숫자 타입 String에 담기  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Posted by Habentius
: