We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. C++
  3. Introduction
  4. Say "Hello, World!" With C++
  5. Discussions

Say "Hello, World!" With C++

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 2757 Discussions, By:

votes

Please Login in order to post a comment

  • Ethan13310
    4 years ago+ 32 comments

    -Don't use 'printf' here, it's a C function. C++ is not C in any way. Use 'std::cout' instead.

    -Never use 'using namespace std'. This directive has been added for compatibility purpose and can lead into multiple definitions in larger projects. It breaks the namespace principle. However, you can use it for literals (e.g. 'using namespace std::chrono_literals'). If you really don't want to use the 'std::' prefix, you can use 'using std::cout', 'using std::endl' and so on for each function, class, etc. you want to import in the global namespace.

    #include <iostream>
    
    int main()
    {
        std::cout << "Hello, World!" << std::endl;
        return 0;
    }
    

    And with 'using':

    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
        cout << "Hello, World!" << endl;
        return 0;
    }
    
    54|
    Permalink
    View more Comments..
  • samplenhold
    4 years ago+ 4 comments

    Weirdest challenge. All I had to do was submit it with no change and it passed.... whatever.

    13|
    Permalink
    View more Comments..
  • Nobbs66
    3 years ago+ 0 comments

    Here's my implementation

    int main()
    {
    	int out[] = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
    	for (int i = 0; i < 12; i++)
    	{
    		char put = static_cast<char>(out[i]);
    		std::cout << put;
    	}
    	
    	return 0;
    }
    
    8|
    Permalink
  • Lauman
    4 years ago+ 6 comments
    #include <iostream>
    using std::cout;
    
    template <typename T> T print(void){
        return "Hello, World!";
    }
    
    int main() {
        cout << print<const char *>();
        return 0;
    }
    
    6|
    Permalink
    View more Comments..
  • pappukutta161
    6 months ago+ 0 comments

    At that point, you'll infrequently go over a venture where a craftsman has made their own deck dependent on a most loved being a fan. Sadly, they're Geeky Deck not liable to be printed because of copyright reasons. I did a touch of burrowing to locate some great decks that you may get a kick out of the chance to have in your own assortment.

    2|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature