dev c++ and turbo c++

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 11661 Views - Last Post: 03 January 2011 - 06:40 PM Rate Topic: -----

#1 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

dev c++ and turbo c++

Posted 07 March 2010 - 10:25 PM

I had turbo c++

now i have dev c++ for trying but the code of additon program which was working in turbo c++ is not working in dev c++

this is the code

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
     int a,b,c;
     cout<<"Enter your number = ";
     cin>>a>>b;
     c=a+b;
     cout<<"your answer is ="<<c;
     getch();
 }



can anybody tell me why

Is This A Good Question/Topic? 0
  • +

Replies To: dev c++ and turbo c++

#2 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 07 March 2010 - 10:25 PM

sorry the question came two times

This post has been edited by thapchi: 07 March 2010 - 10:38 PM

Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: dev c++ and turbo c++

Posted 07 March 2010 - 10:33 PM

Turbo C++ is so out of date and does not follow many standards. So, you have a couple of changes to make. Firstly, <iostream.h> is <iostream> (The first is not standard).
Also, instead of <conio.c> and getch(), simply use cin.
Thirdly, change void main() to int main() and return 0 at the end of it.

#include<iostream>
#include<math.h>
int main()
{
     int a,b,c;
     cout<<"Enter your number = ";
     cin>>a>>b;
     c=a+b;
     cout<<"your answer is ="<<c;
     //Clean the stream and ask for input
     std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
     std::cin.get();
     return 0;
 }


Was This Post Helpful? 0
  • +
  • -

#4 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 07 March 2010 - 10:37 PM

can u tell me what this means

 std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );


and yes one more thing

dev c++ the latest one is not taking iostream

so i changed it to iostream.h

This post has been edited by thapchi: 07 March 2010 - 10:37 PM

Was This Post Helpful? 0
  • +
  • -

#5 Trav  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 210
  • Joined: 01-March 10

Re: dev c++ and turbo c++

Posted 07 March 2010 - 10:39 PM

Also Dev C++ hasn't been updated since 2005, you might be better of to switch.
Was This Post Helpful? 0
  • +
  • -

#6 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 07 March 2010 - 10:44 PM

no problem i will switch but dev c++ is atleast updated than turbo c++

so i prefer i should check my program on dev c++

then i ll switch to latest one

I dont know anything about namespace because in turbo c++ it was not supported at all

so can u tell me

 std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );


what it means
Was This Post Helpful? 0
  • +
  • -

#7 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: dev c++ and turbo c++

Posted 08 March 2010 - 05:07 AM

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');


First of all, numeric_limits is a Class defined in <limits> header file. So, to use the above line, you need to :
#include <limits>



Let's analyze the code a little bit:
#include <iostream>
#include <limits>

int main()
{
	std::cout << std::numeric_limits<std::streamsize>::max();

	return 0;
}


On my computer, the output is 2147483647. Now, std::streamsize is equivalent to "signed int", or "signed long". So, what std::numeric_limits<std::streamsize>::max() does? It returns the maximum value an integer can have. Great, we figured out that. Let's move to std::cin.ignore(): this function discards the remaining characters in buffer. The first parameter is the number of characters to discard. The second parameter represents the delimiting character. So:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');


discards 2147483647 characters with the delimiter of a newline ('\n'). This function is used for a re-implementation of "Press any key to continue ..." method. So use it when you want to keep the console opened, so you can see the output of your program.

This post has been edited by sarmanu: 08 March 2010 - 09:38 AM

Was This Post Helpful? 2
  • +
  • -

#8 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 08 March 2010 - 07:53 AM

but it is a harder method
#include <conio.h>

getch();


It is simple than that i think ?
Was This Post Helpful? 0
  • +
  • -

#9 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:01 AM

In order to use getch(), you have to #include <conio.h>, which is NOT a standard C++ header nor C. Don't use non-standard functions, it's cosidered a bad practice. I must admit, I do not use the numeric_limits method too, I generally use this:
std::cin.ignore();
std::cin.get();
return 0;


Was This Post Helpful? 0
  • +
  • -

#10 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:05 AM

well kindly can u tell me what is numeric_limits method
Was This Post Helpful? 0
  • +
  • -

#11 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:06 AM

I just told you about it earlier in this post ... :)
Was This Post Helpful? 1
  • +
  • -

#12 thapchi  Icon User is offline

  • D.I.C Head

Reputation: -26
  • View blog
  • Posts: 86
  • Joined: 05-February 10

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:09 AM

Oh ya found it Thanks again
Was This Post Helpful? 0
  • +
  • -

#13 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:24 AM

See one of the big problems with learning with Turbo C/C++ is that it is very old and pre-dates the standard. So you will need to learn a few new things to work in modern compilers.

First of all the standard headers no longer have a .h extension.

that is why it is: #include <iostream> without the .h

The C library headers have been renamed by dropping the .h and prefixing 'c'

math.h becomes cmath
stdio.h becomes cstdio
stdlib.h becomes cstdlib
time.h becomes ctime
ctype.h becomes cctype

what about conio.h -- does it become cconio? -- No it does not, because conio.h is non-standard (although most windows compilers support using it -- but we are not supposed to talk about that). So there are still .h files (for example third party libraries, and your own .h files).

Another thing you should do in standard C++ is use "int main()" rather than "void main()" -- the compilers will generally still let you use void main() but it is non-standard and should be avoided.

so your program would be:
#include<iostream>
#include<conio.h>

using namespace std;


int main()
{
     int a,b,c;
     cout << "Enter your two numbers to add: ";
     cin >> a >> b;
     c = a + b;
     cout << "your answer is = " << c << endl;
     getch();
     return 0;
 }


Or of you wanted to avoid using the non-standard conio.h this would become:
#include<iostream>

using namespace std;


int main() 
{
    int a, b, c;
    cout << "Enter your two numbers to add: ";
    cin >> a;
    //ignore the '\n' char
    cin.ignore ();

    cin >> b;
    //ignore the '\n' char
    cin.ignore ();

    c = a + b;
    cout << "your answer is = " << c << endl;
    cin.get();
    return 0;
}



Also note the line using namespace std; -- One of the features of C++ is namespaces which help to avoid naming conflicts. The standard libraries are all placed in a namespace called "std" -- so to use a function or class located within the standard library you need to add "std::" in front of it:

std::cout << "hello world" << std::endl;

as you can imagine this can get tiresome. So the 'using' keyword can be used to import names into the current scope. To add ALL of the names you can use:

using namespace std;

if you only want to include one name you can use:

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

-- as you will discover there are a number of little things you will have to relearn -- this is not specific to Dev-C++ but to modern C++
Was This Post Helpful? 3
  • +
  • -

#14 joesyuh  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 174
  • Joined: 30-September 08

Re: dev c++ and turbo c++

Posted 08 March 2010 - 08:50 AM

I would suggest code::blocks instead of dev c++. I used dev c++ for a long time and code::blocks is very similar.
Was This Post Helpful? 1
  • +
  • -

#15 Guest_kanav*


Reputation:

Re: dev c++ and turbo c++

Posted 03 January 2011 - 09:14 AM

View Postjoesyuh, on 08 March 2010 - 07:50 AM, said:

I would suggest code::blocks instead of dev c++. I used dev c++ for a long time and code::blocks is very similar.

i used clrscr() function in turboc++ ..
but its not working in devc++??
what is its substitute?
Was This Post Helpful? 0

  • (2 Pages)
  • +
  • 1
  • 2