Consider the following piece of code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstddef>
using namespace std;
int main()
{
vector<stringv;
v.push_back("ze ro");
v.push_back("on e");
v.push_back("tw o");
v.push_back("th ree");
v.push_back("te st string");
v.push_back("an other string");
iterator_traits < vector<string>: :iterator >::difference_t ype c
=
count(v.begin() , v.end(), string("test
string"));
cout << c << endl;
int arr[] = { 0, 1, 2, 3, 0, 1, 2 };
ptrdiff_t i = count(arr, arr + (sizeof(arr) / sizeof(arr[0])),
2);
cout << i << endl;
return EXIT_SUCCESS;
}
In the above code, I had to use two different types for the return
type of std::count().
Instead is there a common return type which I can use ?
Also the first return type
iterator_traits < vector<string>: :iterator >::difference_t ype
is lengthy. Is there a shorter form ?
Kindly clarify.
Thanks
V.Subramanian
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstddef>
using namespace std;
int main()
{
vector<stringv;
v.push_back("ze ro");
v.push_back("on e");
v.push_back("tw o");
v.push_back("th ree");
v.push_back("te st string");
v.push_back("an other string");
iterator_traits < vector<string>: :iterator >::difference_t ype c
=
count(v.begin() , v.end(), string("test
string"));
cout << c << endl;
int arr[] = { 0, 1, 2, 3, 0, 1, 2 };
ptrdiff_t i = count(arr, arr + (sizeof(arr) / sizeof(arr[0])),
2);
cout << i << endl;
return EXIT_SUCCESS;
}
In the above code, I had to use two different types for the return
type of std::count().
Instead is there a common return type which I can use ?
Also the first return type
iterator_traits < vector<string>: :iterator >::difference_t ype
is lengthy. Is there a shorter form ?
Kindly clarify.
Thanks
V.Subramanian
Comment