[英]Turbo C++ and Code blocks
Why should I use namespaces and int main in Code blocks while there are no namespaces in turbo c++ and I can use void main without returning any value as I learnt in schools. 为什么我应该在Code块中使用命名空间和int main,而在turbo c ++中却没有命名空间,并且我可以使用void main而不返回我在学校学到的任何值。 Is the compiler different, Is the C++ version different?
编译器是否不同,C ++版本是否不同?
First of all, Turbo C++ is a compiler bundled with an IDE targetting MS-Windows. 首先,Turbo C ++是与面向MS-Windows的IDE捆绑在一起的编译器 。 Code Block is an IDE supporting several compilers and platforms.
代码块是一个IDE,支持多个编译器和平台。 That is the main difference between these two tools, so you are not comparing exactly the same things.
这是这两个工具之间的主要区别,因此您无法比较完全相同的东西。
Secondly, int
is the standard return value for main
, which is also standard by convention in C and C++ for program source code entry points (1) . 其次,
int
是 main
的标准返回值 ,它也是C和C ++中约定的程序源代码入口点(1) 的标准返回值 。 C++ compilers operating in standard mode expect programs to be written that way, so your programs should conform these expectations, if you want to use conforming C++ compilers, which are what Code Block is supporting by default. 在标准模式下运行的C ++编译器期望以这种方式编写程序,因此,如果您要使用兼容的C ++编译器,则程序应符合这些期望,这是Code Block默认支持的功能。 However, I'm pretty sure that you code configure Code Block to use a specific compiler in a non compliant mode (or simply a non compliant compiler), since it is a flexible IDE;
但是,我很确定您将代码块配置为在非兼容模式下使用特定的编译器(或简称为非兼容编译器),因为它是灵活的IDE。 you might well be able to set it up to use Turbo C++, and thus make it compile non ANSI C++.
您可能可以将其设置为使用Turbo C ++,从而使其能够编译为非ANSI C ++。 That said, I don't think that Turbo C++ does not support ANSI C++.
就是说,我不认为Turbo C ++不支持ANSI C ++。
Thirdly, Namespaces are a feature of C++, that you have to use if you want to use the standard C++ library, but nothing forces you to otherwise. 第三,命名空间是C ++的功能,如果要使用标准C ++库,则必须使用命名空间,但是没有其他方法可以迫使您使用。
(1) the name is a convention, but the function itself is obviously necessary. (1)名称是一个约定,但是函数本身显然是必需的。
Possibly you worked on a very old version of compiler that doesn't implement the C++
specifications completely or in other words it is not conformant to C++
. 可能是您使用的是很旧的编译器版本,它没有完全实现
C++
规范,或者换句话说,它不符合C++
。 An old version written during dos era may allow you to do many nasty/non-standard things. 在dos时代编写的旧版本可能会允许您执行许多令人讨厌的/非标准的事情。
In C++
entire C++ standard library is defined within namespace std
. 在
C++
整个C ++标准库都在namespace std
定义。 You must use using
and/or fully qualified name (with scope resolution) to access these. 您必须使用
using
和/或完全限定名称(具有范围解析)来访问这些名称。
main
in C++ must return an int
with either of the 2 signatures C ++中的
main
必须返回带有两个签名之一的int
int main();
int main(int argc, char *argv[]);
In short for your use cases turbo C++
is doing wrong while Codeblocks
is correct. 总之你的用例
turbo C++
做错了,而Codeblocks
是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.