Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 69
  1. #11
    Join Date
    Sep 2004
    Location
    The Netherlands
    Posts
    1,027
    In your first post you say you're learning C++ so I'll give you the C++ code for Hello World.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
         cout << "Hello world\n";
         return 0;
    }
    That's the C++ code, the code you had was C#.

  2. #12
    Join Date
    Mar 2005
    Location
    Lincoln, England (UK)
    Posts
    998
    Quote Originally Posted by Luhoo Zuher
    SG, I'm not 100% sure about this, but it looks like the training materials you are using are teaching to write programs with C style code instead of C++ style code. I gather this because you used stdio.h instead of iostream (using .h in a standard header usually means it is a C header), and also because you are using printf instead of std::cout(or cout and declaring using namespace std; under your includes like CGTalker said). So if your intention is to learn C++, you might want to look into different materials. Not that learning C would be damaging, its just not quite C++. But perhaps CGTalker will be kind enough to verify that what I am saying is true or untrue
    yes, your right, it does indeed look like 'c' instead of the desired 'c++'. But after all c++ is just c with classes (more or less) - however dont under-estimate the power of Object Orientated Programming!
    BTW: If i remember rightly c and c++ can be mixed and still will compile and run nicely under gcc etc.

    trebster: Are you sure this looks like c# programming?
    Also you need to include the following to get the system to display hello world:
    Code:
    system ("pause");
    Cheers
    Alex
    [Pulling out his pump-action shotgun.] Hicks: I like to keep this handy for close encounters.
    Frost: I hear that!
    -Aliens

    Blain: Bunch of slack-jawed faggots around here! This stuff will make you a god damnned sexual Tyrannosaurus, just like me!
    -Predator

  3. #13
    Join Date
    Sep 2004
    Posts
    42
    Quote Originally Posted by trebster
    In your first post you say you're learning C++ so I'll give you the C++ code for Hello World.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
         cout << "Hello world\n";
         return 0;
    }
    That's the C++ code, the code you had was C#.
    I know what's wrong now. Trebster, your code is work. If I name that code to be "My first program" the compiling is successful but I can't open the exe file. If I name it to be "myfirstprogram " the compiling is successful and I also can open the exe file. Now, I know that there should not have "space" in the file name.

  4. #14
    Join Date
    Sep 2004
    Posts
    42
    Thanks cg, the "system ("pause");" is work.

    But i am confused between C and C++. No one teach me C I just learn it in two books. Both of them are written by Ivor Horton. One of them is called "Begining C" and another is called "Beginning Visual C++6".
    Now I know there are different between C and C++.

    If I want to learn C++, should I start to learn C first or just C++ first?
    If I edit C, what compiler should I use?

  5. #15
    Join Date
    Jun 2005
    Location
    Phoenix
    Posts
    66
    It will never hurt you to learn C first, although a few of the sources I have read have suggest that given the choice, jump straight into C++. They say you can pick up some habits in C that turn out to be bad habits in C++.

    Also, the second book you listed "Beginning Visual C++ 6" is written for a specifc compiler, Microsofts Visual Studio. This is not really a "problem," it's just that there will be things in that book specific to Microsofts compiler. Their are only minor differences in language when switching between compilers (the fact that you need to use system("pause") while many others don't is one example). However, adjusting settings is more compiler specific, and since you are using the Dev compiler, when it's starts to tell you how to adjust setting and things like that, you will have to do some research to follow along. Or if you have some money ($100 or so), you can buy Visual Studio (that's what I did, and I don't regret it at all). But just remember, that if you get a version of Visual Studio other than version 6, you'll still have to do some research to figure out how to adjust some of the setting.

    Finally, I imagine the book goes into detail about developing programs using the Windows API, and your programs wouldn't be very cross platform in that case. But maybe that's not your goal.

  6. #16
    Join Date
    Apr 2005
    Posts
    78
    Hopefully this won't spark a huge debate. There's always disagreement over whether C or C++ should be learned first. Ultimately, it doesn't matter. But if C++ is what you're aiming to learn, I say that's what you should focus on.

    And you probably would do well to find a good C++ book that isn't compiler specific. There are plenty of them around. For that matter, there are many, many free tutorials for C++ online, or there's also the option of the VTM's on this site, which I personally find to be the easiest and most effective way to learn. They teach you the "how to" more than the theory behind it, but theory is something naturally picked up through experience, I say.
    "I would like to buy the Talented Ball a drink and perform open-heart surgery together."
    --Albert Einstein

  7. #17
    Join Date
    Mar 2004
    Posts
    0
    Quote Originally Posted by trebster
    In your first post you say you're learning C++ so I'll give you the C++ code for Hello World.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
         cout << "Hello world\n";
         return 0;
    }
    That's the C++ code, the code you had was C#.
    um. erm.... c# code would look like so:
    Code:
    using System;
    class MainClass
    {
        static void main()
        {
            Console.WriteLine("Hello world");
            Console.Read();
        }
    }

    you mean it was c code.
    i believe people should learn c++ first, because i think that languages such as BASIC and C introduce bad habits that would make programing c++ harder


  8. #18
    Join Date
    Sep 2004
    Posts
    42
    Quote Originally Posted by Luhoo Zuher
    It will never hurt you to learn C first, although a few of the sources I have read have suggest that given the choice, jump straight into C++. They say you can pick up some habits in C that turn out to be bad habits in C++.

    Also, the second book you listed "Beginning Visual C++ 6" is written for a specifc compiler, Microsofts Visual Studio. This is not really a "problem," it's just that there will be things in that book specific to Microsofts compiler. Their are only minor differences in language when switching between compilers (the fact that you need to use system("pause") while many others don't is one example). However, adjusting settings is more compiler specific, and since you are using the Dev compiler, when it's starts to tell you how to adjust setting and things like that, you will have to do some research to follow along. Or if you have some money ($100 or so), you can buy Visual Studio (that's what I did, and I don't regret it at all). But just remember, that if you get a version of Visual Studio other than version 6, you'll still have to do some research to figure out how to adjust some of the setting.

    Finally, I imagine the book goes into detail about developing programs using the Windows API, and your programs wouldn't be very cross platform in that case. But maybe that's not your goal.
    1. Do you mean that we should edit different code in different compilers for the same program? (Do you understand what I am talking about? )
    2. Which compilers are not specific?
    3. If my goal of learning C++ is making games, should I learn visual C++?
    4. Does "printf" belong to C language or both C and C++?

  9. #19
    Join Date
    Apr 2005
    Posts
    78
    There are many different compilers for C++, and some of them also support other languages. Strictly speaking, C and C++ are different programming languages, so there is no guarantee you can use the same compiler for both (most good ones will work for either, however).

    Also, remember that the compiler is different from the IDE (integrated development environment). Dev-C++ and Code::Blocks are IDE's, while GCC or Digital Mars are compilers that can be used with the IDE. Visual C++ is a Microsoft product which can refer to either the IDE or the compiler. So, "not compiler-specific" usually means something that doesn't include the word "Visual". In effect it just means that it's information that you should be able to use no matter what compiler or IDE you're using.

    Visual C++ is not a different language than C++, it's merely a different compiler. If you want to learn to program games, yes, you should learn C++, but Visual C++ refers specifically to the Microsoft compiler/IDE product. You can make games just as well with Dev-C++ and GCC, for example, but Visual C++ might possibly be easier to work with.

    printf is a remnant of C, but it can be used in C++, as pretty much all C functions can be. However, in C++ you generally will want to use cout instead. For that you will use the statement "#include <iostream>" instead of "#include <stdlib.h>.
    Edit: Err, sorry, I meant <stdio.h>.
    cout is easier to use and more flexible. printf may be ever so slightly faster than cout, but I and probably most would argue that the difference in speed is not enough to be concerned about.

    I found all this stuff rather confusing when I was first getting started with C++, too, but don't worry, it all comes together with a little practice and familiarity.
    Last edited by Seikima; 07-06-2005 at 08:45 AM.
    "I would like to buy the Talented Ball a drink and perform open-heart surgery together."
    --Albert Einstein

  10. #20
    Join Date
    Jul 2003
    Location
    Reading, UK
    Posts
    1,359
    If you're trying to make a decision about whether to go for c++ over c thyen go for c++. Everything c can do c++ can do as well. The syntax is practically exactly the same and the only reason people would say c++ is any harder that c is because you have to structure and design your code differently to fit in with a OOP way of doing things. But even then, you don't have to. You can write programs with no classes atall.

Page 2 of 7 FirstFirst 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •