C to C++ transition

This is a discussion on C to C++ transition within the C++ Programming forums, part of the General Programming Boards category; This may have already been done before but here is a basic idea of the transition between C++ and C. ...

  1. #1
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32

    C to C++ transition

    This may have already been done before but here is a basic idea of the transition between C++ and C.

    C:
    Code:
    #include <stdio.h>
    int main()
    {
         printf("Hello, world!\n");
         return 0;
    }
    C++:
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    int main()
    {
         cout << "Hello, world!" << endl;
         return 0;
    }
    I hope that answers some basic questions. When you are ready to learn more there is most obviously the rest of the board to browse through to find the help you need.

    trainee
    Last edited by trainee; 01-06-2004 at 07:09 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I suggest you learn before you teach. Your C example is completely undefined and even if it does work, the two examples do not result in the same output. Your C++ example at least conforms to the C++ standard though, kudos for that.
    My best code is written with the delete key.

  3. #3
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    The idea of this post being....? To remind us of why we're here?
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    Originally posted by WDT
    The idea of this post being....? To remind us of why we're here?
    I suppose, if you want to take it that way.

    trainee

  5. #5
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    Originally posted by Prelude
    I suggest you learn before you teach. Your C example is completely undefined and even if it does work, the two examples do not result in the same output. Your C++ example at least conforms to the C++ standard though, kudos for that.
    Did I fix it?

    trainee

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by trainee
    Did I fix it?

    trainee
    Depends on what standard you're conforming to.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284376

    [edit]
    Please don't start another main() usage convo, they tend to go on for ages without actually going anywhere
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Did I fix it?
    Close enough, though most of us would prefer that you use
    Code:
    int main ( void )
    My best code is written with the delete key.

  8. #8
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    Originally posted by Prelude
    >Did I fix it?
    Close enough, though most of us would prefer that you use
    Code:
    int main ( void )
    Okay man, fixed. Thanks for the suggestions, I don't want to hand out false information.

    trainee

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Thanks for the suggestions
    We're always happy to propvide constructive criticism. Let me be the first (I believe at least) to welcome you to our happy little community.
    My best code is written with the delete key.

  10. #10
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Welcome trainee, I was new here not long ago too.

    One piece of advice though, we generally answer questions when asked and don't spontaneously answer random questions. It's cool though.

    One other thing, C++ standard doesn't require "return 0;" at the end of main, but a lot of compilers still do.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  11. #11
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    C++ standard doesn't require return 0;? Wow, that's news to me. Where did you hear this man?

    trainee

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by trainee
    C++ standard doesn't require return 0;? Wow, that's news to me. Where did you hear this man?

    trainee
    In the standard!

    [edit]
    And yeah, the FAQ too.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    But it still has to be int main(void) right?

    trainee

  14. #14
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    int main()

    You don't need void in C++ either.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  15. #15
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    The point being that if the end of the main() function is reached without a return statement, there is an implicit return 0.

    And with int main(void), in C++ an empty parameter list means there are none.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Transition from Java to c++..
    By ankitsinghal_89 in forum Tech Board
    Replies: 13
    Last Post: 05-09-2009, 07:30 PM
  2. Automata Transition Table Generator?
    By audinue in forum C Programming
    Replies: 0
    Last Post: 06-25-2008, 05:30 AM
  3. Transition table
    By The Urchin in forum C++ Programming
    Replies: 3
    Last Post: 10-05-2006, 10:42 AM
  4. cool transition effects?
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 05-30-2003, 01:34 PM
  5. Transition between PP and OOP
    By The Gweech in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2002, 04:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21