您现在的位置是:主页 > news > 百度商桥代码怎么加到网站上/中山360推广

百度商桥代码怎么加到网站上/中山360推广

admin2025/5/10 14:28:33news

简介百度商桥代码怎么加到网站上,中山360推广,阿里云做网站流程,二级域名可以做淘客网站看一篇STL学习的文章,作者为Scott Field ,不知道为什么作者使用count和count_if函数都是使用四个参数,计数放到第四个参数,返回值是bool型。文章中解释的是“每次当第三个条件满足时,把第四个变量加一”。但我查阅MSDN…

百度商桥代码怎么加到网站上,中山360推广,阿里云做网站流程,二级域名可以做淘客网站看一篇STL学习的文章,作者为Scott Field ,不知道为什么作者使用count和count_if函数都是使用四个参数,计数放到第四个参数,返回值是bool型。文章中解释的是“每次当第三个条件满足时,把第四个变量加一”。但我查阅MSDN…

     看一篇STL学习的文章,作者为Scott Field ,不知道为什么作者使用count和count_if函数都是使用四个参数,计数放到第四个参数,返回值是bool型。文章中解释的是“每次当第三个条件满足时,把第四个变量加一”。但我查阅MSDN发现都是三个参数,返回size_t。怀疑是STL标准的版本问题。

(文章地址:http://www.stlchina.org/twiki/bin/view.pl/Main/STLIntroduce)

count_if函数原型如下:

ContractedBlock.gifExpandedBlockStart.gifCode
1template<class InputIterator, class Predicate> inline 
2   size_t count_if(
3      InputIterator First,
4      InputIterator Last,
5      Predicate P
6   )
7

前两个参数是iterator(迭代器),表示查找半闭合区间的前后两个位置,第三个参数为一个用户定义的predicate function object,而predicate意思就是说是一个返回值是bool型的仿函数(function object,也称functor)。

count函数原型如下:

ContractedBlock.gifExpandedBlockStart.gifCode
1template<class InputIterator, class T> inline
2   size_t count(
3      InputIterator First,
4      InputIterator Last,
5      const T& Value
6   )
7

前两个参数如上,只是第三个参数是一个T类型的常量,相比之下,count_if具有更大的灵活性。

一切以MSDN为准,所以使用应改为如下:

ContractedBlock.gifExpandedBlockStart.gifCode
 1ExpandedBlockStart.gifContractedBlock.gif/**//*
 2|| Using a more complex function object
 3*/

 4#include <iostream.h>
 5#include <string>
 6#include <list>
 7#include <algorithm>
 8
 9//predicate function object
10class IsAToothbrush 
11ExpandedBlockStart.gifContractedBlock.gif{
12public:
13  IsAToothbrush(string& InToothbrushCode) : 
14ExpandedSubBlockStart.gifContractedSubBlock.gif      ToothbrushCode(InToothbrushCode) {}
15  bool operator() (string& SalesRecord) 
16ExpandedSubBlockStart.gifContractedSubBlock.gif  {
17    return SalesRecord.substr(0,4)==ToothbrushCode;
18  }
       
19private:
20  string ToothbrushCode;        
21}
;
22
23int main (void
24ExpandedBlockStart.gifContractedBlock.gif{
25  list<string> SalesRecords;
26
27  SalesRecords.push_back("0001 Soap");
28  SalesRecords.push_back("0002 Shampoo");
29  SalesRecords.push_back("0003 Toothbrush");
30  SalesRecords.push_back("0004 Toothpaste");
31  SalesRecords.push_back("0003 Toothbrush");
32  
33  string VariableToothbrushCode("0003");
34
35  int NumberOfToothbrushes(0);
36ExpandedSubBlockStart.gifContractedSubBlock.gif/**//*
37  count_if (SalesRecords.begin(), SalesRecords.end(), 
38              IsAToothbrush(VariableToothbrushCode),
39                 NumberOfToothbrushes);
40*/

41  NumberOfToothbrushes = count_if (SalesRecords.begin(), SalesRecords.end(), 
42              IsAToothbrush(VariableToothbrushCode));
43  cout << "There were  "
44       << NumberOfToothbrushes 
45       << " toothbrushes matching code "
46       << VariableToothbrushCode
47       << " sold" 
48       << endl;
49}

50

编译环境:WINDOWS XP SP3,vs2005

转载于:https://www.cnblogs.com/dyingfire/archive/2009/01/22/1380062.html