So I overloaded the ostream << operator so it can take most STL containers and print them. However, it doesn't work for passing strings (the error is "ambiguous overload" for the line "cout << s;"). How do I make it so it works on strings as if it weren't overloaded?
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& _containerprint(ostream &out, T const &val) {
return (out << val << " ");
}
template<typename T1, typename T2>
ostream& _containerprint(ostream &out, pair<T1, T2> const &val) {
return (out << "{" << val.first << " " << val.second << "} ");
}
template<template<typename, typename...> class TT, typename... Args>
ostream& operator<<(ostream &out, TT<Args...> const &cont) {
for(auto&& elem : cont) {
_containerprint(out, elem);
}
return out;
}
int main() {
string s = "help me";
cout << s;
}
Edit: please stop freaking out, the #include <bits/stdc++.h>
is because it's for a programming contest setting; it really doesn't matter!