#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <tuple>
void printBoard(std::vector<std::tuple<int,int>> x) {
for (unsigned int i = 0; i < x.size(); i++) {
int trying = std::get<0>(x[i]);
int num = std::get<1>(x[i]);
std::cout << "Case #" << trying << ", Val = $" << num << std::endl;
}
}
int main()
{
std::cout << 5 << std::endl;
}
我试着运行这段代码,但在尝试运行这些代码时,我得到了这些错误:
DealOrNoDeal.cpp:7:34: error: no member named 'tuple' in namespace 'std'
void printBoard(std::vector<std::tuple<int,int>> x) {
~~~~~^
DealOrNoDeal.cpp:7:43: error: expected '(' for function-style cast or type construction
void printBoard(std::vector<std::tuple<int,int>> x) {
~~~^
DealOrNoDeal.cpp:7:51: error: expected '>'
void printBoard(std::vector<std::tuple<int,int>> x) {
^
DealOrNoDeal.cpp:7:28: note: to match this '<'
void printBoard(std::vector<std::tuple<int,int>> x) {
^
DealOrNoDeal.cpp:7:34: error: no member named 'tuple' in namespace 'std'
void printBoard(std::vector<std::tuple<int,int>> x) {
~~~~~^
DealOrNoDeal.cpp:7:43: error: expected '(' for function-style cast or type construction
void printBoard(std::vector<std::tuple<int,int>> x) {
~~~^
DealOrNoDeal.cpp:7:51: error: expected '>'
void printBoard(std::vector<std::tuple<int,int>> x) {
^
DealOrNoDeal.cpp:7:28: note: to match this '<'
void printBoard(std::vector<std::tuple<int,int>> x) {
^
DealOrNoDeal.cpp:8:34: error: use of undeclared identifier 'x'
for (unsigned int i = 0; i < x.size(); i++) {
^
DealOrNoDeal.cpp:9:34: error: use of undeclared identifier 'x'
int trying = std::get<0>(x[i]);
^
DealOrNoDeal.cpp:10:31: error: use of undeclared identifier 'x'
int num = std::get<1>(x[i]);
这真的很奇怪因为我以前从来没有遇到过这个代码段的问题..。我正试图建立一个交易或没有交易的游戏,但它所做的只是带来多个错误。我有什么办法解决这个问题吗?
发布于 2022-06-11 22:39:08
您所得到的错误是因为您使用了错误的C++版本。
std::tuple
模板在C++11中添加。
要修复此错误,建议更改编译器配置中的C++版本。我在VSC中使用msys64 mingw64 g++,可以编译这段代码而不会出错。
如何安装:https://code.visualstudio.com/docs/cpp/config-mingw
您还可以告诉clang使用以下选项进行编译:-std=c++11
发布于 2022-06-12 03:08:45
无论如何,我只是使用这个命令来让我的代码正常工作:
clang++ -std=c++11 -stdlib=libc++ DealOrNoDeal.cpp
我试着遵循另一个提到的步骤,但是做不到,因为microsoft应用程序不能用MacOS打开。
https://stackoverflow.com/questions/72588177
复制相似问题