1
지금 STL (C++)을 배웠습니다.C++, STL의 간단한 함수기
다음 코드에서는 정수 요소 [0; 110]가있는 벡터가 있고 나머지 벡터 요소 수를 25로 나눌 수 있습니다.
1
2
3
4
5
카운터 : 0
왜 0
프로그램 난 다음 출력을 볼 수 있습니다를 실행 한 후?
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
class dividesby
{
int counter;
public:
int getCounter(){return counter;}
dividesby():counter(0){}
void operator()(int i)
{
if(i%25==0)
{
counter++;
std::cout<<"\n"<<counter<<"\n";
}
}
};
void main()
{
using namespace std;
vector <int> v;
for(int i=0;i<110;i++)
{
v.push_back(i);
}
dividesby D;
for_each(v.begin(),v.end(),D);
cout<<"Counter: "<<D.getCounter()<<"\n";
}
for_each