Search code examples
coutendl

Just starting off with C++, not registering command


I'm not really sure why "cout" and "endl" are not being recognized. Any help would be great!

The error is: enter image description here

and the code is: enter image description here


Solution

  • The fact that iostream has a red squiggle underneath it is a near certainty that you have something wrong with your environment (such as compiling with a C compiler rather than a C++ one, for example).

    You need to fix that, since cout and endl are defined in that header. I'd start by hovering the mouse over the iostream text and see what the tooltip shows you.

    If it cannot find the file iostream then you're either not using a C++ compiler, or your environment is severely damaged.

    Either way, it's not a correct C++ environment.

    Things to look in to are (to start with):

    • Examine the file extension. Using *.c instead of *.cpp may use a C compiler rather than a C++ one, for example).
    • Examine the output of your compilation, if available. You will hopefully be able to tell which compiler is being used.

    If you are sure you're using a C++ compiler:

    • You might have a funny character in your iostream string. You could totally delete that line and retype it (don't edit, it may not get rid of the funny character).
    • Try a different header (like cstdlib) to see if it has the same problem.
    • Last-straw solution would be re-installation of your development environment, in case things are so damaged it's unrecoverable.