C++ STL容器

发布于 2024-08-28 09:25:34 字数 238 浏览 4 评论 0原文

不同的STL容器如向量堆栈集合队列等支持不同的访问方法。

例如,如果您在 Notepad++vim 中进行编码,则必须不断参考文档以了解所有可用方法,至少我必须这样做。

有没有一些好方法来记住哪个容器支持哪些方法?

Different STL containers like vector, stack, set, queue, etc support different access methods on them.

If you are coding for example in Notepad++ or vim, you have to continuously refer to the documentation to see what all methods are available, atleast I have to.

Is there some good way of remembering which container supports which methods??

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

情徒 2024-09-04 09:25:34

方法的名称并不是为了不同而不同。它有助于记住哪些容器有哪些方法,以及理解名称的含义。例如,push_back 对于集合来说是无意义的。 insert 在谈论堆栈时没有任何意义(当然堆栈也没有正面或背面,所以它不支持 push_back,只是 <代码>推)。对于向量来说,两者都有明确定义的含义,因此向量同时支持 insertpush_back

The names of the methods aren't different for the sake of being different. It helps in remembering which containers have which methods, to understand the meaning of the name. push_back for example is nonsensical in relation to sets. insert doesn't make any sense when talking about stacks (of course stacks don't have a front or a back either, so it doesn't support push_back, just push). For a vector, both have a well-defined meaning, so vector supports both insert and push_back.

久伴你 2024-09-04 09:25:34

充分使用它们,以便记住每种方法的方法。

Use them enough so that you remember the methods of each.

白色秋天 2024-09-04 09:25:34

如果您的记忆力一直不好,请尝试将所有这些内容的参考保留在另一个窗口中。如果您有多个显示器,那么在第二台显示器上放置类似的内容(用于任何类型的文档)确实非常方便。

另外,我强烈推荐具有智能感知功能的真正编码 IDE! Notepad++ 可能太简单,无法在 C++ 中提高工作效率。

If your memory keeps failing you, try keeping a reference of them all up in another window. If you have more than one monitor, it's really handy to have stuff like this on a second monitor (for documentation of any kind).

Alternatively I highly recommend a real coding IDE with intellisense! Notepad++ is probably too simple for being productive in C++.

笑饮青盏花 2024-09-04 09:25:34

使用内置智能感知的工具,例如 Windows 上的 Visual Studio 或 Linux 上的 KDevelop。

还有 vim 和 emacs 的附加组件用于智能感知。

Use something that has built in intellisense such as Visual Studio on Windows or KDevelop on Linux.

There are also add-ons for vim and emacs for intellisense.

鸠书 2024-09-04 09:25:34

即使你记住了所有“方法”,那也只是故事的一部分。为了有效地使用STL,您还需要了解算法。我建议阅读一本好书(Stroustrup、Josuttis,...)中有关 STL 的内容,以便记住可用的内容,然后在需要确切语法时返回书籍或打开参考站点。

Even if you remember all the "methods", that is only one part of the story. To effectively use STL, you need to know algorithms as well. I would suggest reading about STL in a good book (Stroustrup, Josuttis, ...) to just remember what is available, and then return to the books or have reference site open when you need the exact syntax.

黒涩兲箜 2024-09-04 09:25:34

这可能不是您正在寻找的内容,但 Scott Meyers(因“Effective C++”而闻名)根据 Nicolai Josuttis 的书“The C++ Standard Library”编制了以下 STL 算法列表:

Josuttis 的 STL 算法总结

This may not be exactly what you're looking for, but Scott Meyers (of "Effective C++" fame) has compiled the following list of STL algorithms based on Nicolai Josuttis's book "The C++ Standard Library":

Josuttis’ Summary of STL Algorithms

抽个烟儿 2024-09-04 09:25:34

了解它们是什么以及常用方法,然后就很容易记住哪些方法适用。 STL 并不完全一致,但已经相当不错了。

Learn what they are, and the common methods, and then it should be fairly easy to remember which ones apply. The STL isn't perfectly consistent, but it's pretty good.

肩上的翅膀 2024-09-04 09:25:34

承认它不支持记忆,你可以在 vim 上运行某种智能感知。优点是您可以从自己的和外部的源代码文件创建标签。无论如何,STL 需要特殊处理,如下所述。

下载这些 vim 脚本 OmniCppCompleteSuperTab

安装 OmniCppComplete:

  • 将插件解压到 ~/.vim。

安装 SuperTab:

  • 在 vim 中打开文件 ($ vim supertab.vba)。
  • 获取文件源 (:so %)。

通过您最喜欢的包管理器安装 ctags。下载并解压此文件并在其上运行ctags。

$ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ tags_stl cpp_src 

这将生成一个名为“tags_stl”的 ctags 文件,其中包含 STL 标签。将其复制到您喜欢的任何地方。将以下尚未存在的行添加到 ~/.vimrc 中:

set tags+=~/path/to/your/tags_stl  
filetype on  
filetype plugin on  
let OmniCpp_GlobalScopeSearch=1  
let OmniCpp_NamespaceSearch=2  
let OmniCpp_MayCompleteDot=1  
let OmniCpp_MayCompleteArrow=1  
let OmniCpp_MayCompleteScope=1  
let OmniCpp_DisplayMode=1  
let OmniCpp_DefaultNamespaces=["std"]

这将完成 'tab'、'.'、'::' 和 '->' 上的 STL 语句即使在“使用命名空间 std;”时也是如此。如果您讨厌洋红色,请不要这样做。

Admitting that it doesn't support remembering you can get some kind of intellisense running on vim. The advantage is that you can create tags from both own and external source code files. Anyhow STL needs a special treatment which is described here.

Download these vim-scripts OmniCppComplete and SuperTab.

Install OmniCppComplete:

  • Unzip the plugin to ~/.vim.

Install SuperTab:

  • Open the file in vim ($ vim supertab.vba).
  • Source the file (:so %).

Install ctags via your favourite package manager. Download and unpack this file and run ctags on it.

$ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ tags_stl cpp_src 

This will generate a ctags file named 'tags_stl' containing the STL-Tags. Copy it anywhere you like. Add the following lines which do not already exist to your ~/.vimrc:

set tags+=~/path/to/your/tags_stl  
filetype on  
filetype plugin on  
let OmniCpp_GlobalScopeSearch=1  
let OmniCpp_NamespaceSearch=2  
let OmniCpp_MayCompleteDot=1  
let OmniCpp_MayCompleteArrow=1  
let OmniCpp_MayCompleteScope=1  
let OmniCpp_DisplayMode=1  
let OmniCpp_DefaultNamespaces=["std"]

This completes STL statements on 'tab', '.', '::' and '->' even when 'using namespace std;'. Don't do it if you hate magenta.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文