(学习C++)为什么我的编译器在我尝试造成元组时会报告错误?

发布于 2025-02-11 07:02:13 字数 1095 浏览 0 评论 0原文

我是C ++的新手,并在来自Python背景后的今年夏天借此自由学习了。我正在观看有关如何在C ++中创建和使用元组的视频,并且它似乎对YouTuber有效,但是当我复制他的步骤时,我的编译器即使在代码

代码上没有明显的差异,

#include <iostream>
#include <string>
#include <tuple>

int main() {

    std::tuple <int, std::string> person(18, "Chris");
    std::cout << std::get<1>(person) << std::endl;

    return 0;
}

但我的编译器也引发了一些错误:错误 :错误:错误:错误:错误:错误:错误:错误:错误: :

❯ g++ -o main Tuples.cpp && ./main
Tuples.cpp:7:10: error: no member named 'tuple' in namespace 'std'
    std::tuple <int, std::string> person(18, "Chris");
    ~~~~~^
Tuples.cpp:7:20: error: expected '(' for function-style cast or type construction
    std::tuple <int, std::string> person(18, "Chris");
                ~~~^
Tuples.cpp:8:30: error: use of undeclared identifier 'person'
    std::cout << std::get<1>(person) << std::endl;
                             ^
3 errors generated.

参考视频:

I'm new to c++ and have taken the liberty to learn it this summer after coming from a python background. I was watching a video about how to create and use tuples within c++ and it seemed to have worked for the YouTuber, however when I replicated his steps, my compiler had thrown some errors even though there was no distinct differences in the code

code:

#include <iostream>
#include <string>
#include <tuple>

int main() {

    std::tuple <int, std::string> person(18, "Chris");
    std::cout << std::get<1>(person) << std::endl;

    return 0;
}

Errors:

❯ g++ -o main Tuples.cpp && ./main
Tuples.cpp:7:10: error: no member named 'tuple' in namespace 'std'
    std::tuple <int, std::string> person(18, "Chris");
    ~~~~~^
Tuples.cpp:7:20: error: expected '(' for function-style cast or type construction
    std::tuple <int, std::string> person(18, "Chris");
                ~~~^
Tuples.cpp:8:30: error: use of undeclared identifier 'person'
    std::cout << std::get<1>(person) << std::endl;
                             ^
3 errors generated.

Video for reference: https://www.youtube.com/watch?v=T9-agjKW4PQ&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=16

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文