G
Griff
#include <iostream>
using namespace std;
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
template<class C>void PrintAll(C&v)
{
typename C::iterator i;
for (i = v.begin(); i!= v.end(); ++i)
{
cout << *i << endl;
}
}
void main()
{
const string s1 = "First line";
const string s2 = "Second line";
const string s3 = "Third line";
vector<string> V;
V.push_back(s1); V.push_back(s2); V.push_back(s3);
for_each(V.begin(),V.end(),PrintAll);
}
=============================================================
I won't bore you (yet) with the reams of complaint from MS VC++ when I
try to compile the above...
My question is:
What is the correct syntax to use "for_each" to call the function
template PrintAll ?
for_each(V.begin(),V.end(),PrintAll<const string>); ??
for_each(V.begin(),V.end(),PrintAll); ??
or is it even possible ?
Assistance and explanation would be welcomed on this.
Best regards,
Griff
using namespace std;
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
template<class C>void PrintAll(C&v)
{
typename C::iterator i;
for (i = v.begin(); i!= v.end(); ++i)
{
cout << *i << endl;
}
}
void main()
{
const string s1 = "First line";
const string s2 = "Second line";
const string s3 = "Third line";
vector<string> V;
V.push_back(s1); V.push_back(s2); V.push_back(s3);
for_each(V.begin(),V.end(),PrintAll);
}
=============================================================
I won't bore you (yet) with the reams of complaint from MS VC++ when I
try to compile the above...
My question is:
What is the correct syntax to use "for_each" to call the function
template PrintAll ?
for_each(V.begin(),V.end(),PrintAll<const string>); ??
for_each(V.begin(),V.end(),PrintAll); ??
or is it even possible ?
Assistance and explanation would be welcomed on this.
Best regards,
Griff