【发布时间】:2022-01-09 15:39:28
【问题描述】:
我是学习计算机科学的学生,刚开始编程。使用 VSCode 时遇到问题。 这是我的 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;
}
}
当我编辑 no operator ">>
问题是我已经用命令完美地编译了文件(没有发现错误)
g++ -std=c++20 main.cpp -o main
然后我用这个命令重新编译
g++ -std=c++14 main.cpp -o main
编译器开始像 VSCode 一样显示错误。
很明显,这不是错误,如何更改VSCode使用的C++版本?
【问题讨论】:
-
您编辑 c_cpp_properties.json 文件用于智能感知和 tasks.json 用于构建。该文档在此处解释了这两个文件:https://code.visualstudio.com/docs/cpp/config-mingw
-
@Evg 感谢您的关注,但这不是我的问题。对我来说没什么大不了的,我在 Compete Contest 中使用 C++
-
地图有3个模板参数,运算符>>重载都不合适。
-
这就是为什么它只是一个评论而不是一个答案。请注意,您的代码将来可能会被其他人发现,这就是为什么我们不应该在问题中传播臭名昭著的不良做法。尤其是那些刚开始编程的人。
标签: c++ visual-studio-code c++17 c++14 c++20