Jump to content

Recommended Posts

Posted

C++ is just an extension of C language which include Object Oriented Programming (with classes) and some new features you can use or not (like stream operators ">>" and "<<")

iostream contains standard C libraries so you can use C functions too.

The difference between the C and C++ is more a point of view than a real language :

C++ is used for Oriented Object programs while C is used for linear programming ("base de donnée relationnelle" in French, I don't know the term in English).

Posted

C++ is just an extension of C language which include Object Oriented Programming (with classes) and some new features you can use or not (like stream operators ">>" and "<<")

iostream contains standard C libraries so you can use C functions too.

The difference between the C and C++ is more a point of view than a real language :

C++ is used for Oriented Object programs while C is used for linear programming ("base de donnée relationnelle" in French, I don't know the term in English).

 

No.

 

If you want to program professionally, you will need to think and realise that C and C++ are different languages. They are used very differently and only similarities are in the syntax.

 

iostream has absolutely nothing to do with standard C

Posted (edited)

C standard library is not compatible with the C++ memory handling. The proper way to include C functions is to take the .h off from the C library header and add c in front of the name (e.g. #include <ctype.h> --> #include <cctype> )

 

Ok, maybe I'm splitting hairs to some degree, but the main point is that C++ is not C nor C with classes. C++ is significantly different and it is programmed using templates and other language constructs that are not present in C. These make it more different then just an idea of C with classes. C with classes was a programming style in the 90's and between C and C++ programming. This is not what the C++ is good for.

 

It is usually recommended to anyone learning C++ to not to mix C language into it at all. It is not needed. One should use the C++ constructs from the very start.

Edited by ge_f
Posted

ge_f what is the point of your argument. Yes we know C++ came from C. C went to C with classes and after heavy standardization and additions it became C++. Like it or not C++ came from C. The heart of what Nico said is true- he never mentioned iostream involving C. Besides this topic is one about a simple problem I encountered with my logic in my first program. If you want to split hairs and argue the virtues of C vs C++ make a different topic.

Posted (edited)

Please read both of our posts again.

 

I clearly mentioned C++ came from C.

 

Nico clearly said iostream includes C standard library.

 

I may have missed what the heart of what Nico said was. However, he clearly said they are the same language, the difference is only point of view. It is very bad to mix these languages, you end up making the least efficient code with no benefits from either language and even worse, you easily end up making bugs one would not make if he would stick with one of the languages. If the classes or objects are the point of C++, then C language works just as well for it with structs.

 

My point is, if it matters, that one can learn programming C++ and probably even learns it better without mixing C language to it.

 

I didn't attack against Nico, just what he said may confuse people learning and possibly even be counter helpfull in learning the language the way it should be programmed.

 

Also, you can define the operators "<<" and ">>" to do what ever you want. Not only with streams but with any of your own classes. Thats one of the little things I like in the C++, it gives so much possibilities when writing the programs.

 

EDIT:

If you want to split hairs and argue the virtues of C vs C++ make a different topic.

 

You may want to direct that to someone who posted before me. Because I have only argued within the ongoing discussion.

Edited by ge_f
  • Like 1
Posted

Sorry if I misunderstood what you were saying aboutthe libraries. The comment about arguing over them though was targeted at no one specifically- just saying before this thread turns into a bunch of spam arguing over the C variants.

Posted

Hmm, you do have to think of C++ as a different language, I have used C++ compilers that would not allow standard C functions used.. as for learning C++ without C, I dunno about all that, I Learned C before C++ was around.

  • 3 months later...
Posted

Sorry this answer is so late compared to the question, but I just saw the question.

 

You include <iostream> in the program to include the classes for input output stream.

This provides you with the ability to call cin and cout.

cin is console input and allows the program to get keyboard input.

cout displays the text to the screen.

 

In basic C you included stdio.h and to write to the screen was done with a printf () command.

 

You can modify this program to keep asking for the number until the user guess the proper number, and provide an exit as follows:

 

---------------------------------------------------------

#include <iostream>

using namespace std;

 

int main()

{

int x, found = 0;

 

while (!found) // we will loop until found is set to true

{

cout << "Guess what number I am thinking of between 1 and 10: Enter 0 to exit";

cin >> x;

cin.ignore();

 

if (x < 1 || x > 10)

cout << "That is an invalid entry !!";

else if (x == 0)

{

cout << "Exiting";

found = 1;

}

else if (x == 7)

cout << "Very good you must be psychic.\n";

else

cout << "Sorry you guessed wrong.\n";

}

}

 

------------------------------------------------------------------------

By the way I have been a software engineer for 30 years and have been coding in C and C++ for 27 years

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.