Can anyone see anything wrong with this from a standard C++ point of view:
#include <iostream>
#include <string>
#include <map>
#include <iterator>
using namespace std;
void addToMap(map<in t,string>& m,int index, const char* str)
{
string strcast(str);
pair<int,string > p (index,str);
m.insert(p);
}
ostream& operator << (ostream& os, const pair<int,string >& p)
{
os << p.first << ": " << p.second << endl;
return os;
}
int main(void)
{
map<int, string> strings;
addToMap(string s,3,"Hello");
addToMap(string s,5,"World");
ostream_iterato r< pair<int,string > > out_it(cout,"") ;
copy(strings.be gin(),strings.e nd(),out_it); /* won't compile */
return 0;
}
This is not actually my code, but that of a poster to a forum. After
screwing up a response to that post, I'd like to help find an answer. :)
If you want to see the thread:
Thanks in advance.
--
Derek
#include <iostream>
#include <string>
#include <map>
#include <iterator>
using namespace std;
void addToMap(map<in t,string>& m,int index, const char* str)
{
string strcast(str);
pair<int,string > p (index,str);
m.insert(p);
}
ostream& operator << (ostream& os, const pair<int,string >& p)
{
os << p.first << ": " << p.second << endl;
return os;
}
int main(void)
{
map<int, string> strings;
addToMap(string s,3,"Hello");
addToMap(string s,5,"World");
ostream_iterato r< pair<int,string > > out_it(cout,"") ;
copy(strings.be gin(),strings.e nd(),out_it); /* won't compile */
return 0;
}
This is not actually my code, but that of a poster to a forum. After
screwing up a response to that post, I'd like to help find an answer. :)
If you want to see the thread:
Thanks in advance.
--
Derek
Comment