首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我不知道为什么这个代码不起作用?

我不知道为什么这个代码不起作用?
EN

Stack Overflow用户
提问于 2022-06-11 22:13:17
回答 2查看 109关注 0票数 -3
代码语言:javascript
运行
复制
#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;
}

我试着运行这段代码,但在尝试运行这些代码时,我得到了这些错误:

代码语言:javascript
运行
复制
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]);

这真的很奇怪因为我以前从来没有遇到过这个代码段的问题..。我正试图建立一个交易或没有交易的游戏,但它所做的只是带来多个错误。我有什么办法解决这个问题吗?

EN

回答 2

Stack Overflow用户

发布于 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

票数 3
EN

Stack Overflow用户

发布于 2022-06-12 03:08:45

无论如何,我只是使用这个命令来让我的代码正常工作:

代码语言:javascript
运行
复制
clang++ -std=c++11 -stdlib=libc++ DealOrNoDeal.cpp

我试着遵循另一个提到的步骤,但是做不到,因为microsoft应用程序不能用MacOS打开。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72588177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档