我使用的是哪个版本的 C++?
What version of C++ am I using?
我正在学习 C++ 编程 class,我大学提供的 C++ classes 的 2/2,我问我的教授我们使用的是哪个版本的 C++,他不知道.
我在这里四处寻找,发现了一堆基于 G++ 的不同答案,不支持某些版本并支持某些此版本的 C++,等等-...
我的一般问题:
我使用的是哪个版本的 C++?
我可以使用哪些版本的 C++?
我使用的C++版本的优缺点?
我现在是否应该担心 C++ 的不同版本?
g++ --version
的输出:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
我当前的 G++ 编译器版本:4.2.1
IDE:Eclipse C++ 2020-03
OS:MacOSX MoJave
我们用于 class 的代码片段:
void find(int IDs[], string posts[], int size)
{
int search = -9999;
bool found = false;
cout << "Enter user ID: " << endl;
cin >> search;
while (search < 0)
{
cout << "In-correct ID Type" << endl;
cout << "Enter user ID: " << endl;
cin >> search;
}
cout << "Posts by user " << search << ":" << endl;
cout << endl;
for (int i = 0; i < size; i++)
{
if (IDs[i] == search)
{
cout << *(posts + i);
found = true;
}
}
if (found == false)
{
cout << "N/A posts for user " << search << endl;
}
cout << endl;
}
根据 gcc 4.2.4 manual:
standard may be one of:
...other options omitted for brevity...
- c++98
The 1998 ISO C++ standard plus amendments.
- gnu++98
The same as -std=c++98 plus GNU extensions. This is the default for C++ code.
没有为有效的 C++ 版本提供其他选项。
您的默认 C++ 版本是: C++98(加上 gnu 扩展!不管是什么意思)
您可能的 C++ 版本选项是: C++98(加上 gnu 扩展)
- What version of C++ am I using ?
如果您使用默认设置,可能是 GNU C++ 98(注意:与 (标准)ISO C++ 98 不同)
- What versions of C++ can I use?
gcc 4.2.4 仅支持 ISO C++ 98 和 GNU C++ 98
- Advantages and disadvantages of C++ version I am using?
第一个 ISO 标准化版本,顾名思义在 1998 年左右发布。
此后发布了重大修订。
非常古老和笨重,但仍大量存在于行业中。
后来的修订使该语言更加优雅和易于使用,
如果可能,还至少使用 ISO C++ 11 (2011)(也称为 现代 C++)或更高版本,这被认为是最佳实践。
- Should I even worry about the different versions of C++ right now?
如果您参加 class 主要是学习语言而不是编程基础...
尤其是如果您打算积极使用 class 之外的语言...
是
但由于了解以后的修订细节可能具有挑战性,至少现在知道主要差异是什么。
--
参考文献:gcc 4.2.4 manual
从g++ --version
的输出...
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
看来您实际上使用的是 clang++
10.0.1。这应该对语言规范有好处。根据 this table 以及一些选定的 c++20 功能,高达并包括 c++17。
我正在学习 C++ 编程 class,我大学提供的 C++ classes 的 2/2,我问我的教授我们使用的是哪个版本的 C++,他不知道.
我在这里四处寻找,发现了一堆基于 G++ 的不同答案,不支持某些版本并支持某些此版本的 C++,等等-...
我的一般问题:
我使用的是哪个版本的 C++?
我可以使用哪些版本的 C++?
我使用的C++版本的优缺点?
我现在是否应该担心 C++ 的不同版本?
g++ --version
的输出:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
我当前的 G++ 编译器版本:4.2.1
IDE:Eclipse C++ 2020-03
OS:MacOSX MoJave
我们用于 class 的代码片段:
void find(int IDs[], string posts[], int size)
{
int search = -9999;
bool found = false;
cout << "Enter user ID: " << endl;
cin >> search;
while (search < 0)
{
cout << "In-correct ID Type" << endl;
cout << "Enter user ID: " << endl;
cin >> search;
}
cout << "Posts by user " << search << ":" << endl;
cout << endl;
for (int i = 0; i < size; i++)
{
if (IDs[i] == search)
{
cout << *(posts + i);
found = true;
}
}
if (found == false)
{
cout << "N/A posts for user " << search << endl;
}
cout << endl;
}
根据 gcc 4.2.4 manual:
standard may be one of:
...other options omitted for brevity...
- c++98
The 1998 ISO C++ standard plus amendments.
- gnu++98
The same as -std=c++98 plus GNU extensions. This is the default for C++ code.
没有为有效的 C++ 版本提供其他选项。
您的默认 C++ 版本是: C++98(加上 gnu 扩展!不管是什么意思)
您可能的 C++ 版本选项是: C++98(加上 gnu 扩展)
- What version of C++ am I using ?
如果您使用默认设置,可能是 GNU C++ 98(注意:与 (标准)ISO C++ 98 不同)
- What versions of C++ can I use?
gcc 4.2.4 仅支持 ISO C++ 98 和 GNU C++ 98
- Advantages and disadvantages of C++ version I am using?
第一个 ISO 标准化版本,顾名思义在 1998 年左右发布。 此后发布了重大修订。
非常古老和笨重,但仍大量存在于行业中。
后来的修订使该语言更加优雅和易于使用, 如果可能,还至少使用 ISO C++ 11 (2011)(也称为 现代 C++)或更高版本,这被认为是最佳实践。
- Should I even worry about the different versions of C++ right now?
如果您参加 class 主要是学习语言而不是编程基础...
尤其是如果您打算积极使用 class 之外的语言...
是
但由于了解以后的修订细节可能具有挑战性,至少现在知道主要差异是什么。
--
参考文献:gcc 4.2.4 manual
从g++ --version
的输出...
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
看来您实际上使用的是 clang++
10.0.1。这应该对语言规范有好处。根据 this table 以及一些选定的 c++20 功能,高达并包括 c++17。