1

I'm using turboc++ 4.0 and Visual studio 2013. I just started learning programming. when I write the code.

#include<iostream.h>
#include<conio.h>
int main()
{
cout<<"hello!";
getch();
return 0;
}

it works well in turbo, but visual stdio shows an error

fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory.

and when I use

using namespace std;

it shows another error about using getch();.

Does every compiler have its own syntax?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Possible duplicate of [Why can't g++ find iostream.h?](https://stackoverflow.com/questions/13103108/why-cant-g-find-iostream-h) – phuclv Aug 12 '18 at 11:36

2 Answers2

3

"Does every compiler have it's own syntax?"

No, there's a standard every compiler needs to implement.
Turbo-C++ was made before any standards were established and is merely the only compiler still around, that doesn't implement them.

The standard compliant way to write your program looks like:

#include <iostream>

int main() {
    std::cout<<"hello!" << std::endl;
    char dummy;
    std::cin >> dummy;
}

Note: You shouldn't use using namespace std;, but explicitly put the std:: scope when needed, or use using std::cout cout;, etc.

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • The note is very bad advice in two ways: (1) our language features are there for us to use as appropriate, and `using namespace std;` is often appropriate, where one appropriate case is the one of making pre-standard code work with modern compilers, and (2) it gives the impression that such *don't think, just follow a mechanical rule blindly* approach is useful and practical. It isn't. The end result of blindly following mechanical rules is very low quality, complex code, and much wasted time. – Cheers and hth. - Alf Jun 18 '16 at 19:11
  • In particular, in the present case, the work to qualify all relevant identifiers in the case with `std::`, can be prohibitive. So it's very bad advice indeed. – Cheers and hth. - Alf Jun 18 '16 at 19:13
3

Turbo C++ is from the middle or early 1990's, before the standardization of C++.

At that time the effective standard for C++ was the ARM, the Annotated Reference Manual by Bjarne Stroustrup and Margaret Ellis (IIRC), and it used <iostream.h>.

With the first standardization in 1998 <iostream.h> was dropped, and replaced with just <iostream>. The standard header places cin and cout in namespace std, so you can't just change the header name. It's not guaranteed, but you may possibly be able to make your code work by writing

#include <iostream>
using namespace std;
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331