#include <ctime>
#include <vector>
#include <iostream>
#include <atlstr.h>

using namespace std;

struct tagRand
{
	int nCount;
	CString strRand;
};

int main( )
{
	srand( (unsigned)time(NULL) );
	
	int nInput(1);
	vector<tagRand> vecNum;

	//데이터 입력
	for( int i=0 ; i<10 ; ++i )
	{
		tagRand oTemp;

		oTemp.nCount = i+1;
		oTemp.strRand.Format( TEXT("%d"), rand( )%8 );

		vecNum.push_back( oTemp );
	}

	printf( "0을 입력하면 종료됩니다.\n\n" );

	while( nInput != 0 )
	{	
		//입력된 데이터 출력
		for( int i=0 ; i<vecNum.size( ) ; ++i )
		{
			printf( "%d, %s\n", vecNum[i].nCount, vecNum[i].strRand );
		}

		printf( "삭제할 수를 입력하세요 : " );
		scanf( "%d", &nInput );
		printf( "\n" );
		
		//선택한 항목 삭제
		//vector<tagRand>::iterator iter = vecNum.begin( );
		auto iter = vecNum.begin( );
		while( iter != vecNum.end( ) )
		{
			if( iter->nCount == nInput )
			{ 
				iter = vecNum.erase( iter );				
			} 
			else 
			{ 
				++iter; 
			} 
		}
		system( "cls" );
	}

	return 0;
}


+ Recent posts