D
Derek Baker
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<int,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(strings,3,"Hello");
addToMap(strings,5,"World");
ostream_iterator< pair<int,string> > out_it(cout,"");
copy(strings.begin(),strings.end(),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:
http://sourceforge.net/forum/forum.php?thread_id=973964&forum_id=48211
Thanks in advance.
#include <iostream>
#include <string>
#include <map>
#include <iterator>
using namespace std;
void addToMap(map<int,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(strings,3,"Hello");
addToMap(strings,5,"World");
ostream_iterator< pair<int,string> > out_it(cout,"");
copy(strings.begin(),strings.end(),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:
http://sourceforge.net/forum/forum.php?thread_id=973964&forum_id=48211
Thanks in advance.