5월27일 C++(순수가상함수,sort,setf(ios_base::boolalpha,showpos,hex,width)API(비트맵뷰어)

2010. 5. 27. 08:592010년/5월

반드시 자식 클래스는 부모클래스의 vitual되어있는 함수를 구현해야한다.
그것이 바로 순수가상함수라는것이다.


보다 시피 itisn에서 virtual void test()함수를 만들고 뒤에 0을 넣었다.

그러면 자식이되는 sca에서  test()함수를 반드시 구현해야한다.

만약에 sca test()함수 자체를 빼거나 주석처리하게 되면 에러가 뜬다.

이는 개발자의 의도 하는것이다.

뭐 강제적으로 하는것이니깐.










Sort
일단 알고리즘이라는것을 전처리하고 정렬에 대한내용이다 기본적으로 정렬이나 연결리스트나 이런 대한 자세한 내용이 있는 라이브러리 함수가 있다 그중에서 정렬같은경우 sort를 사용하는데

다른내용은없다 기본적으로 캐릭터 배열에서 들어간 내용을 알파벳 순서에 맡게 정렬하는내용이다

여기서 string을 넣고 sort()를 사용했다.
sort의 첫번째 인자는 시작주소이고 마지막 인자는 끝주소이다

그래서 첫인자로 String을넣었고
마지막 주소를 sizeof(String)-1로 넣어서 했더니 결과값이
이렇게 나왔다.











#include
<iostream>
#include<list>

//연결리스트 
using namespace std;

int main()
{

  std::list<int>intList; //표준템플릿 라이브러리를 선택해서 int형으로 intList 연결리스트 만듬

  for(int i=0;10>i;++i)
  {
    intList.push_back(i); //연결리스트계속 꼬리 물듯이 뒤로 붙음 
  }
  intList.remove(5);    //해당되는 찾아서 삭제 즉 5가 삭제..

  std::list<int>::iterator it;
  for(it=intList.begin();it!=intList.end();++it) //begin()연결리스트의 제일 시작주소 
  {
    std::cout<<*it<<endl;//객체의 데이터를 뽑아낸다. <<는 연산자 오버로딩 
  }
  return 0//연결리스트가 자동으로 정리가 된다. 
}
================================================================
================================================================
#include<iostream>
using
 namespace std;
int main()
{
  ios_base::fmtflags Old;
  cout<<true<<endl;
  cout.setf(ios_base::boolalpha);
  cout<<true<<endl;
  cout.unsetf(ios_base::boolalpha);//해제 
  cout<<boolalpha<<true<<endl;//일회용 
//*******************************************************
  cout<<10<<endl;
  cout<<-10<<endl;
  
  cout.setf(ios_base::showpos);
  cout<<10<<endl;
  cout<<-10<<endl;
  cout.unsetf(ios_base::showpos);//해제 
  cout<<showpos<<10<<endl; //일회용 
//*******************************************************
  cout<<99<<endl;
  cout.setf(ios_base::hex,ios_base::basefield);
  cout<<99<<endl;
  cout.setf(Old,ios_base::basefield);//해제 
  cout<<hex<<99<<endl;  //일회용 
  cout<<dec<<99<<endl;
//*******************************************************
  cout.width(10);      //일회용 
  cout<<100<<endl;
  cout.fill('*');    //별붙이기 
  cout.width(10);    // 일회용 
  cout<<100<<endl;
//*******************************************************
  cout<<true<<endl;
  cout<<10<<endl;
  return 0;
}