Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to add a few things so that the program works like you intend.</p> <p>The line #include tells the compiler that you'd like to include the contents of the IOStream library header in your program. This header is what provides "cout", "&lt;&lt;", and plenty of other input / output functionality. However, the tokens "cout" and "&lt;&lt;" exist in the "std" namespace. This means that if you don't use "std::cout", the compiler doesn't know <em>which</em> cout you want to use, so it gets confused.</p> <p>The solution to that part is to just add the line "using namespace std;" beneath the #include line. This tells the compiler that the above headers should automatically use the "std" namespace. This is kind of like automatically putting "std::" in front of all of the tokens included from the library. This may not be a fatal error for all compilers ( testing it just now on GCC doesn't give me an error... ), but you may run into errors from not specifying a namespace in the future.</p> <p>The second issue is that the main function needs to be called main. When your program runs, it runs by beginning the 'main' function, and ends when 'main' returns. However, if there is no function called 'main', there's no entry point for the program and no way for it to run. This is probably just a typo, but it'll still confuse the compiler.</p> <p>Next, for the output to be pretty, you'll probably want to put either a "\n" or an "endl" at the end of the 'cout' statement, so that a newline will be printed after the string "Hello world". Strictly speaking, this won't prevent the program from compiling or running, but it's good to get used to ending your output with newlines.</p> <p>Finally, as Christian Ternus already pointed out, since main() is declared as an int, it has to have a return value. Declaring a function (like main) as an int says that the function, when called, mathematically evaluates to an integer. In the context of main(), the value you have main return is the return value of the program when it terminates. Typically, main returns 0 to indicate no failure.</p> <p>Here's your finished version:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(){ cout &lt;&lt; "Hello world" &lt;&lt; endl; return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload