Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't a simple "Hello World"-style program compile with Turbo C++?

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; } 

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?

like image 400
n. 1.8e9-where's-my-share m. Avatar asked Jul 01 '17 16:07

n. 1.8e9-where's-my-share m.


People also ask

Will the program compile in Turbo C?

Turbo C is one such compiler for windows operating system. If you are running a Linux operating system, you can use the GCC compiler. A compiler does the job of converting codes written in C language to machine language, so that it can be executed.

Can we compile C programs in Turbo C++?

In the previous article, you learned how to install a Turbo C++ compiler on a windows system. After installation you must write your first C program ,and compile it. In this article you will learn to compile your first C program. Prerequisite to this article is installing turbo C++ compiler on your windows computer.

Can you compile C program in C++ compiler?

If the compiler uses C++ to compile C code you might have issues if in the C code you use words that are reserved in C++. Will compile fine with a C compiler (or C++ compiler in C mode), but will not compile with a C++ compiler.


1 Answers

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.

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; } 

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.

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

  1. You will be learning a language that is somewhat similar to a popular language used in the industry, but is very different nevertheless, for no good reason. If you plan to write C++ for real software development, you will have to re-learn much. It is much easier to learn modern C++ right away.
  2. There's no extant literature about Turbo C++. Nearly 100% of C++ material you will find on the internet or in the books is not directly applicable to Turbo C++ out of the box. Some will need only minor adaptation, while other material is completely unusable. Pretty much the only source of help immediately available to you is the built-in Turbo C++ help.
  3. Few people remember Turbo C++. When asking questions on forums, always specify that you are using a pre-ANSI dialect in order to filter out responses geared towards the modern version of the language. You will probably get a bunch of comments suggesting you to stop immediately and switch to a modern compiler with every question you ask.

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 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++.

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.

like image 177
n. 1.8e9-where's-my-share m. Avatar answered Sep 24 '22 15:09

n. 1.8e9-where's-my-share m.