gpt4 book ai didi

c++ - 无法打开源文件 "swap.h"

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:43 27 4
gpt4 key购买 nike

我正在完成一项学校作业,但在使用 swap.h 时遇到问题。我知道通常这样的事情是外部依赖项,但在 Visual Studio 2010 中,我没有在我的外部依赖项列表中看到它。我不确定在哪里可以找到它或如何将它添加到列表中以便我可以使用交换功能。有没有人可以在这里为我指明正确的方向?

#include "swap.h"

这只是为了简单地展示我是如何尝试包含该文件的。

最佳答案

so I can use the swap function

std::swap() 来自 the C++ Algorithm library

  • 在 header 中定义<algorithm> (直到 C++11)
  • 在 header 中定义<utility> (C++11 起)

在 Visual Studio 2010 中,您可能需要:

#include <algorithm>

以下评论:

调用std::swap()因此,启用 :

using std::swap;
swap(theArray[index], theArray[nextIndex]);

进一步阅读: How to provide a swap function for my class?

关于c++ - 无法打开源文件 "swap.h",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15192123/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com