I am student studying Computer science just started programming. I am having an issue when using VSCode. Here is my main.cpp:
#include <bits/stdc++.h>
using namespace std;
template <template <typename, typename> class C, typename K, typename V>
std::ostream &operator<<(std::ostream &os, C<K, V> a)
{
os << "[ ";
for (auto t : a)
{
os << t << " ";
}
os << "]";
return os;
}
template <template <typename> class V, typename T>
std::ostream &operator<<(std::ostream &os, V<T> a)
{
os << "[ ";
for (T t : a)
{
os << t << " ";
}
os << "]";
return os;
}
template <typename T, typename V>
std::ostream &operator<<(std::ostream &os, pair<T, V> a)
{
os << "[" << a.first << ", " << a.second << "]";
return os;
}
template <typename T>
std::istream &operator>>(std::istream &is, vector<T> &a)
{
for (T &t : a)
{
is >> t;
}
return is;
}
template <typename T, typename V>
std::istream &operator>>(std::istream &is, pair<T, V> &a)
{
is >> a.first >> a.second;
return is;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
int t = 1;
// cin >> t;
while (t--)
{
vector<int> a(5);
map<int, int> b;
for (int i = 0; i < 5; i++)
{
a[i] = i * 2;
b[i] = i * 2;
}
cout << a << endl;
cout << b << endl;
}
}
VSCode shows error on line 73 when I editting that no operator "<<" matches these operands -- operand types are: std::ostream << std::map<int, int, std::less, std::allocator<std::pair<const int, int>>>
The problem is I have compile the file perfectly (no error found) with command
g++ -std=c++20 main.cpp -o main
then I recompile with this command
g++ -std=c++14 main.cpp -o main
the compiler was starting show error like VSCode did.
Obvious, it's not an error, how do I change the version of C++ that VSCode used?