0

I'm new in C++, and I try to print 'Hello world'.

#include <iostream>

using namespace std;

int main() {
    cout << 'Hello world!';
    return 0;
}

But in result I got '1919706145'. What I'm doing wrong?

neatnick
  • 1,489
  • 1
  • 18
  • 29
Andrii Rusanov
  • 4,405
  • 2
  • 34
  • 54
  • For more information on single and double quotes: http://stackoverflow.com/questions/7459939/what-do-single-quotes-do-in-c-when-used-on-multiple-characters – Atle May 06 '13 at 13:12
  • 2
    It's a very good idea to enable compiler warnings. That should at least tell you that something's not right here, although it might be difficult to figure out what it means at first. – Mike Seymour May 06 '13 at 13:12

3 Answers3

10

Strings are represented by ", not '

#include <iostream>

using namespace std;

int main() {
    cout << "Hello world!"; // Use " not '
    return 0;
}
olevegard
  • 5,294
  • 1
  • 25
  • 29
3

You should use:

cout << "Hello World!" << endl;

Use ' ' for characters not strings. Characters are single alphabets like 'h', 'i', etc while string is "hi".

Cool_Coder
  • 4,888
  • 16
  • 57
  • 99
2

Try doing :

cout << "Hello world!"; // <---------Double Quotes

Strings use double quotes. Single quotes are for single characters.

asheeshr
  • 4,088
  • 6
  • 31
  • 50