S
subramanian100in
Consider the following piece of code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstddef>
using namespace std;
int main()
{
vector<string> v;
v.push_back("zero");
v.push_back("one");
v.push_back("two");
v.push_back("three");
v.push_back("test string");
v.push_back("another string");
iterator_traits< vector<string>::iterator >::difference_type 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_type
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<string> v;
v.push_back("zero");
v.push_back("one");
v.push_back("two");
v.push_back("three");
v.push_back("test string");
v.push_back("another string");
iterator_traits< vector<string>::iterator >::difference_type 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_type
is lengthy. Is there a shorter form ?
Kindly clarify.
Thanks
V.Subramanian