everything worked for me in turbo c++ but not in g++. tell me why do i always have to use "using namespace std;" while compiling with g++? also there is no conio.h, so how do i use the command: getch () then?

everything worked for me in turbo c++ but not in g++. tell me why do i always have to use "using namespace std;" while compiling with g++? also there is no conio.h, so how do i use the command: getch () then?

i installed libconio but how to use it?

turbo c++ is an ancient compiler that uses obsolete c++ header files and follows obsolete c++ standards. Bring yourself into the 21st century and learn how to write modern c++ code.

That is one of the problems with learning to program using ancient turbo c and turbo c++. You switch to a modern compiler and you have to unlearn almost everything you thought you knew.

conio.h is specific to turbo c and Microsoft. Don't expect the rest of the world to follow suite.

Edited 6 Years Ago by Ancient Dragon: n/a

First off C++ has evolved in the last 10 years, hence some changes. These changes were because of unforeseen problems that occurred.

Let us start with why using namespace std; and why you might not want to do that anyway.

What happens in that there are a large number of standard library types, classes and functions that are available via a large number include files. Many of these names are relatively simple, e.g. max, min etc. In the same way that you don't declare everything global, you don't want the who symbol table polluted with names. Therefore, they are put in a namespace (std). That way you can select the symbols you are going to use and not accidentally introduce a "difficult to find" bug by using a global symbol. e.g.

using std::cout;
using std::endl;

Or you can explicitly type the namespace at the point of use, e.g.

std::cout<<"this is a test"<<std::endl;

However, you have the option to go back to the old way, and type using namespace std; . Obviously, you can do the same for all the other namespaces that you import. However, if you get into difficulties by name pollution...sorry you only have yourself to blame. :) [Note for small projects, you will be fine, but bigger projects don't work]. Also note that all the using commands are scoped, so you can have it globally, or just for one section etc. That is why you should not put them in an include file.

So that leaves us with getch(). That is an old compiler extension with certain compilers. [windows mainly ?? ]. However, if you want the same functionality, but in a standard cross platform manor use std::cin.get() . You will need to add a #include <iostream> .

Additionally, you may have to add a few more includes to your files, since they have tightened up the include everything and the kitchen sink approach that was done in the early days, in which just about any standard include would include all other files. [note: there is still not sufficiently file separation for my liking!!]

If you get stuck compiling your code, do post a piece and we can see what we can suggest.

Edited 6 Years Ago by StuXYZ: n/a

ok! do you have a good ebook on the modern c++ (i use g++ compiler). if so then please provide the link. can anyone suggest a command for how to get a temporary halt so that i advance to the next line after pressing the enter key. that's why i used getch(). (i now use g++ compiler.)

First off C++ has evolved in the last 10 years, hence some changes. These changes were because of unforeseen problems that occurred.

Let us start with why using namespace std; and why you might not want to do that anyway.

What happens in that there are a large number of standard library types, classes and functions that are available via a large number include files. Many of these names are relatively simple, e.g. max, min etc. In the same way that you don't declare everything global, you don't want the who symbol table polluted with names. Therefore, they are put in a namespace (std). That way you can select the symbols you are going to use and not accidentally introduce a "difficult to find" bug by using a global symbol. e.g.

using std::cout;
using std::endl;

Or you can explicitly type the namespace at the point of use, e.g.

std::cout<<"this is a test"<<std::endl;

However, you have the option to go back to the old way, and type using namespace std; . Obviously, you can do the same for all the other namespaces that you import. However, if you get into difficulties by name pollution...sorry you only have yourself to blame. :) [Note for small projects, you will be fine, but bigger projects don't work]. Also note that all the using commands are scoped, so you can have it globally, or just for one section etc. That is why you should not put them in an include file.

So that leaves us with getch(). That is an old compiler extension with certain compilers. [windows mainly ?? ]. However, if you want the same functionality, but in a standard cross platform manor use std::cin.get() . You will need to add a #include <iostream> .

Additionally, you may have to add a few more includes to your files, since they have tightened up the include everything and the kitchen sink approach that was done in the early days, in which just about any standard include would include all other files. [note: there is still not sufficiently file separation for my liking!!]

If you get stuck compiling your code, do post a piece and we can see what we can suggest.

cool. excellent explanation. But, i desperately need an e-book (modern one). all the books i have are linked with turbo c++

replace getch() with std::cin.get() and include <iostream> header file.

As for ebooks -- try this

wow how did you create that web page???? well thanks to all the thread is solved.

This question has already been answered. Start a new discussion instead.