How to start C Programing with Dev C++

C, C++, Visual C++, C++.Net Topics
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: How to start C Programing with Dev C++

Post by Nipuna » Sun Oct 31, 2010 12:01 am

Tick C++ and Make Default language both.

Then the Default Compiler would be C++.

Ask Neo About C. He will tell the deference of C and C++.

As I remember Neo said that When we Write codes without Classes it would be a C Program.
And As I remember When we Add Header files.
we add
#include<iostream>
in C++

But In C We add
#include<iostream.h>

I might be wrong because I've seen some C++ codes with #include<iostream.h>

For Clear Guide ask Neo. He Knows Better Than Me about those :). I will tell you things that I know :) I am not an
Expert of the Subject.

Thanks
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to start C Programing with Dev C++

Post by Neo » Sun Oct 31, 2010 10:12 am

#include<iostream>
in C++

But In C We add
#include<iostream.h>
iostream.h is a C++ header file. We don;t have that in C. In C we use, stdio.h
I might be wrong because I've seen some C++ codes with #include<iostream.h>
No difference in using with .h and without .h in C++. In C, we always need to use .h

One other interesting point is about using <> and "" for include files.
If the path is defined to the compiler already (path is known to compiler), you can use <>. But if the path is not known, then you need to mention the exact path which should go within "".
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Sun Oct 31, 2010 5:28 pm

Thanks NIPUNA & NEO.I read your posts.Now I am trying to make that HELLO WORLD in DEV C++.I will post my first program progress soon.

:)
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Fri Nov 05, 2010 10:22 am

Hi friends.
I start my first programm in C++.
This is it.But I have a problem.

Code: Select all

//first testing programm in C++ by G-sparkz

#include<iostream>
using namespace std;

int main()
{
    cout<<"I am learning C++!";
    return 0;
    }
I compiled it.Its says DONE.
How can I run my code.When I do EXECUTE>RUN
Nothing happens.Just one dialog box came & wanish.
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: How to start C Programing with Dev C++

Post by Nipuna » Fri Nov 05, 2010 1:57 pm

That's Because your Program doesn't make for that. I mean it's only work is Print the Word you add and then automatically exit.
It happened to me too. I asked Neo He gave me the solution it is.
add

Code: Select all

cin.get();
Before

Code: Select all

 return 0;
or you can add

Code: Select all

system("pause");
But if you add this one you Program will print this at the end of the program

Code: Select all

Press any key to continue
But the Best thing i say to add is

Code: Select all

cin.get();
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to start C Programing with Dev C++

Post by Neo » Fri Nov 05, 2010 1:58 pm

I understand the problem. There is nothing holding the output window to stay visible.
You can do two things.
  1. Easy way is, execute (Usually Ctrl+F5) the application (Not Debug which is initiated with F5 normally). In Visual C++ we have the following icons.
    execute.PNG
    execute.PNG (1.49 KiB) Viewed 7975 times
    debug.PNG
    debug.PNG (892 Bytes) Viewed 7975 times
    Or else you can open a command window yourself and run the exe file that was compiled.
  2. Cool way is to let the program wait for a user input. So the screen will hold until you enter something.
    You can use following code.

    Code: Select all

    //first testing programm in C++ by G-sparkz
    
    #include<iostream>
    using namespace std;
    
    int main()
    {
        int i;
    
        cout<<"I am learning C++!";
        cin >> i; // wait until a number is entered from keyboard
    
        return 0;
    }
    
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Fri Nov 05, 2010 4:11 pm

Wow.Cool,It works.I am loving C more & more.It feels good.:)
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Sat Nov 06, 2010 2:35 pm

I wrote my second program in C.
here it is.

Code: Select all

//my second testing programm in C++

#include<iostream>
using namespace std;
int main()
{
    cout<<"I am learing C++  ";
    cout<<"going to test second programm";
    cin.get();
    return 0;
    }
1.I wanna know hot to brake a line in the program.?
2.what is the different between cin.get(); & system("pause");
3.please explain the code cin >> i;
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to start C Programing with Dev C++

Post by Neo » Sat Nov 06, 2010 6:31 pm

1.I wanna know hot to brake a line in the program.?
There are two ways to do this.
  1. cout << "Text on first line" << endl << "Text on second line";
  2. cout << "Text on first line \nText on second line";
In C++, end/endl command is preferred since causes cout buffer to be flushed and displayed instantly to the screen.
2.what is the different between cin.get(); & system("pause");
cin.get() waits until you enter something using keyboard and press enter so it can get the input back to program.
"pause" only wait until you press any key. Try to open the command prompt and enter pause to see what it is. system("pause"); calls the same DOS thing.
3.please explain the code cin >> i;
As said before, cin gets an input from keyboard. Here it get the input (which should be a number) to variable i.
If you print it using following command after cin, you will understand that.

Code: Select all

count << "I entered " << i << " from keyboard.";
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Tue Nov 09, 2010 9:57 pm

Thanks For the help NEO.
This is my newest code.

Code: Select all

//my third testing programm in C++

#include<iostream>
using namespace std;
int main()
{
    int a,b;
   a=10;
   b=20;
    cout<<"I am learing C++  "
    <<endl<<"going to test third programm"
    <<endl<<"my first variable test "
    <<endl<<"my variables are a & b  "<<endl;
    cout<<"this is my variable [a] = "<<a<<endl;
    cout<<"this is my varianle [b] = "<<b<<endl;
    cout<<"I nam going to add my variables"<<endl;
    cout<<"[a] + [b] = "<<a+b<<endl;
    system("pause");
    return 0;
    }
Post Reply

Return to “C/C++ Programming”