为什么简单的“ Hello World”风格的程序无法用Turbo C ++编译? [英] Why doesn't a simple "Hello World"-style program compile with Turbo C++?

查看:125
本文介绍了为什么简单的“ Hello World”风格的程序无法用Turbo C ++编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始为编程课学习C ++。我已经下载了此 Hello World程序:

I have started learning C++ for my programming class. I have downloaded this "Hello World" program:

#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello, World!";
    return 0;
}

但是Turbo C ++抱怨:

but Turbo C++ complains:

Error D:\HELLO.CPP 1: Unable to open include file 'IOSTREAM'
Error D:\HELLO.CPP 2: Declaration syntax error
Error D:\HELLO.CPP 6: Undefined symbol 'cout'

这是怎么了很简单的程序?我该如何纠正这些错误?

What's wrong with this very simple program? How can I correct these errors?

推荐答案

该程序没有问题。 (除了可能存在一些样式问题外,不建议使用
使用命名空间std )。问题出在Turbo C ++。这是一个非常古老的软件。它实现了C ++的方言,即所谓的 pre-ANSI C ++ ,该方言在本世纪初已经完全不再使用。第一个C ++ ANSI标准于1998年发布,然后有2003年版本,2011年版本,2014年版本,2017年版本,现在我们希望2020年版本正式发布。这些标准修订中的每一个都或多或少地对该语言进行了更改。

There's no problem with this program. (Except probably some stylistic issues — using namespace std is not recommended). The problem is with Turbo C++. It is a very old piece of software. It implements a dialect of C++, so-called pre-ANSI C++, that has completely fallen out of use by the beginning of this millennium. The first ANSI standard for C++ was published in 1998, then there was the 2003 version, the 2011 version, the 2014 version, the 2017 version, and now we expect the 2020 version to be officially published. Each of these standard revisions brought more or less significant changes to the language.

对于Turbo C ++,您必须像这样修改程序:

For Turbo C++ you have to modify the program like this:

#include <iostream.h>      // note the .h suffix
// using namespace std;    // Turbo C++ doesn't implement namespaces

int main() 
{
    cout << "Hello, World!";
    return 0;
}

如果您看一下这个程序,现代C ++方言和Turbo C ++接受的一种似乎很小。但是,随着您的程序变得越来越复杂,它会变得越来越大。

If you look at this program, the difference between the modern C++ dialect and the one accepted by Turbo C++ may seem small. However it will grow much larger as your programs will be getting more complex.

虽然您可以使用Turbo C ++学习编程,但我强烈建议您避免这样做,因为存在以下问题:

While you can learn programming using Turbo C++ I would strongly recommend to avoid that if humanly possible because of the following problems:


  1. 您将学习一种与行业中流行的语言有些相似的语言,但是却有很大的不同,没有充分的理由。如果您打算为实际的软件开发编写C ++,则必须重新学习很多东西。立即学习现代C ++更加容易。

  2. 没有关于Turbo C ++的现有文献。您可以在Internet或书籍中找到的几乎100%的C ++资料并非直接适用于Turbo C ++。有些仅需稍作修改,而其他材料则完全无法使用。内置的Turbo C ++帮助几乎是您可以立即获得的唯一帮助资源。

  3. 很少有人记得Turbo C ++。在论坛上提问时,请始终指定您使用的是ANSI前方言,以便过滤出针对现代语言的响应。您可能会收到一堆评论,建议您立即停止并使用遇到的每个问题切换到现代编译器。

有许多现代免费软件(如啤酒以及语音)编译器和IDE,您可以使用它们代替Turbo C ++。其中一些包括:

There are many modern free (as in beer, as well as in speech) compilers and IDEs you can use in place of Turbo C++. Some of these include:


  1. Visual C ++ Community Edition 是IDE和Microsoft的编译器

  2. 代码::块是轻量级的IDE。在Windows上,它附带了有些过时的编译器,但是您可以自己安装更现代的编译器

  3. Eclipse CDT 是功能强大的跨平台IDE。它没有附带自己的编译器,因此您需要安装单独的编译器。在Windows上,例如 MinGW

  4. 更多

  5. 此外,还有很多在线编译器,例如 http://ideone.com https://www.onlinegdb.com/ http ://coliru.stacked-crooked.com/ ,外加更多(大多数方法非常适合尝试点子并编写非常小的程序)。

  6. 两者均 Clang / LLVM GCC 免费软件战争e 支持最新版本C ++的编译器。

  1. Visual C++ Community Edition is an IDE and a compiler from Microsoft
  2. Code::Blocks is a lightweight IDE. On Windows it ships with a somewhat outdated compiler, but you can install a more modern compiler yourself
  3. Eclipse CDT is a powerful cross-platform IDE. It doesn't ship with its own compiler so you need to install a separate compiler. On Windows, use e.g. MinGW.
  4. Many more
  5. In addition, there are many online compilers such as http://ideone.com, https://www.onlinegdb.com/ and http://coliru.stacked-crooked.com/, plus many more (these are mostly good for trying out ideas and writing very small programs).
  6. Both Clang/LLVM and GCC are free software compilers supporting recent versions of C++.

遗憾的是,有些学校/教师甚至强迫学生甚至使用Turbo C ++。当今年代。不幸的是,这不是该社区可以解决的。如果您发现自己处在这种情况下,请准备不能够获得太多外部帮助。

Regrettably, some schools/teachers appear to force students to use Turbo C++ even in this day and age. Unfortunately this is not something this community can fix. If you find yourself in this situation, prepare to not being able to get much outside help.

这篇关于为什么简单的“ Hello World”风格的程序无法用Turbo C ++编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆