Hello World, in C++. menu

Shout-Out

User Tag List

Page 3 of 3 FirstFirst 123
Results 31 to 41 of 41
  1. #31
    dragonowner's Avatar Member
    Reputation
    5
    Join Date
    Jul 2008
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    Like all the others, here we go!

    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "Hello worldn";
    return 0;
    }
    The first line, "#include <iostream>" includes the library iostream, which is used later, for the command "std::cout". If we removed it, we would get that "std" isn't an class or namespace, and that "cout" has an undeclared identifier (std).

    The next line, "int main()" creates the main function, this function is needed in EVERY C++ program.

    Next line, "{" shows where the main() function start.

    Next line, "std::cout << "Hello world!n";
    "std" is the identifier for "cout", without "std::" infront of it, we would get a nasty error. We could actually have added "using namespace std;" after "#include <iostream>", and we wouldn't have to use "std::" anywhere in our program. "cout" is used to show something on the screen. "<<" Those two are needed before we show something on the screen, and the next i'm sure you can guess what does. The "n" part specifies a line-break. Instead of "n", we could've used "std::cout << "Hello world!" std::endl;" which makes it end the line (endl = end line).
    The next line, "}" closes the main() function.
    That was the legendary Hello World program in C++.


    Ur code is messed up its supposed to be

    Code:
    #include <iostream.h>
    
    int main()
    {
           cout << "Hello World!/n";
                  return 0;
    }
    Last edited by dragonowner; 09-02-2008 at 08:08 AM.

    Hello World, in C++.
  2. #32
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    #include <iostream>
    
    int main()
    {    
        std::cout << "\a" << std::endl;
    }
    why do i have to put \\ to make a single backslash in the code tags?..
    Last edited by Jens; 08-29-2008 at 12:54 AM.

  3. #33
    Mewhywhy's Avatar Banned
    Reputation
    19
    Join Date
    May 2008
    Posts
    108
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jezus and i tought C++ whas easy hah guess im worng jezus christ so much code for a dos prompt saying Hello world .... amg

  4. #34
    dragonowner's Avatar Member
    Reputation
    5
    Join Date
    Jul 2008
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what the heck is the std::???

  5. #35
    arigity's Avatar Banned
    Reputation
    49
    Join Date
    Dec 2007
    Posts
    548
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cout and endl are part of the std namespace, you need to tell the compiler this so you add std:: (or add using namespace std

  6. #36
    breezy22's Avatar Member
    Reputation
    1
    Join Date
    Jul 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by dragonowner View Post
    Ur code is messed up its supposed to be

    Code:
    #include <iostream.h>
    
    int main()
    {
           cout << "Hello World!n";
                  return 0;
    }
    And yours is messed up also.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
           cout << "Hello World!" << endl;
           return 0;
    }
    This is how I would do it.
    Last edited by breezy22; 09-04-2008 at 07:32 PM.

  7. #37
    dragonowner's Avatar Member
    Reputation
    5
    Join Date
    Jul 2008
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea i messed up one character but yours is either a weird looking 1 after end its its and l and before using namespace std wouldnt you use //? becuase there is nothing really to direct the namespace to am i right?

  8. #38
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by dragonowner View Post
    yea i messed up one character but yours is either a weird looking 1 after end its its and l and before using namespace std wouldnt you use //? becuase there is nothing really to direct the namespace to am i right?
    no you're not, proofread your comments they're a bit hard to decrypt.
    also <iostream> & \n or std::endl;

  9. #39
    Dragon[Sky]'s Avatar Anti-social Engineer
    Reputation
    847
    Join Date
    Apr 2007
    Posts
    1,416
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you using endl? I'd rather use \n than endl.
    Besides, endl calls flush() function == more memory usage.


  10. #40
    breezy22's Avatar Member
    Reputation
    1
    Join Date
    Jul 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Dragon[Sky] View Post
    Why are you using endl? I'd rather use n than endl.
    Besides, endl calls flush() function == more memory usage.
    Yea, because everyone knows you're worried about memory usage on your first C++ program!

  11. #41
    Dragon[Sky]'s Avatar Anti-social Engineer
    Reputation
    847
    Join Date
    Apr 2007
    Posts
    1,416
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not about the memory usage of a Hello world prog. It becomes a habit.
    Personal experience.


Page 3 of 3 FirstFirst 123

Similar Threads

  1. "Hello World" to making bots & hacks
    By Hi on helium in forum Programming
    Replies: 5
    Last Post: 11-14-2009, 07:33 PM
  2. Hello World!
    By Pragma in forum Programming
    Replies: 8
    Last Post: 03-24-2008, 06:32 PM
  3. Hello World, in DarkBASIC
    By ReidE96 in forum Programming
    Replies: 0
    Last Post: 03-14-2008, 06:26 PM
  4. Hello world !
    By tttommeke in forum Programming
    Replies: 4
    Last Post: 03-09-2008, 10:53 AM
All times are GMT -5. The time now is 10:23 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search