c++ - STL 库在不同平台上是否有所不同?
问题描述
Windows 上的 C++ 标准模板库 (STL) 与 Linux 或任何其他平台上的不同吗?STL 的标头是否也因平台而异,或者 STL 只是一个标头库及其在 CRT 中的实现?
我们知道编译器因平台而异,C 运行时库也因平台而异。这样一来,即使标准模板库(STL)也因平台而异,这是真的吗?
请澄清这个疑问。
另外,Windows 上的 C++ STL 的名称是什么,Linux 上的名称是什么?
我一直在尝试通过在线阅读各种文章并尝试在脑海中构建一个工作流程以更好地理解这些术语来理解这一点。
解决方案
The specification of the C++ Standard Library is not contingent on any particular platform or compiler, although it does depend on the target C++ standard, and its behaviour is dependent function on various properties of a platform.
But the implementation of the C++ Standard Library is extremely dependent on the compiler and operating system. Some of the C++ Standard Library can even hardcoded into compilers.
But you use it in the same way. E.g. for std::cout
and std::cin
you should always write #include <iostream>
as that's what the documentation says you're supposed to do. The names of header files can vary between implementations, but the ones you are supposed to use directly never differ.
This is why it's a good idea not to rely on #include
s being available implicitly via other headers, or by using fancy non-standard #include
s like <bits/...>
. If you do so then you are not writing portable C++.
推荐阅读
- python - 备份脚本不会遍历文件夹中的文件
- apache-spark - Play Cassandra Netty Server null pointer exception
- python - Why do I need a shell script to run a python script inside the container?
- webforms - 在 WebForms 中使用 Open ID 或 Identity Server4 进行单点登录
- swift - 返回从 HTTP 请求中检索到的值的方法
- ansible - Ansible command using variable input fails to execute
- angular - 如何防止任何键盘事件及其对Angular 6中元素的默认行为
- python - 网络抓取不断更新 Python 中的数据
- java - Java Mail 下载大型 IMAP 邮件
- r - 在绘图中标记特定点