1

As one can see, I am just starting out with C++ and just began my hello world program.

    #include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << end1;
    cout << "Hooray!" << end1;

    system("PAUSE");
    return 0;
}

But for some reason, unknown to me, I am getting an error on both of the cout lines, saying end1 was undeclared! How do I fix this?

neatnick
  • 1,463
  • 1
  • 20
  • 29
Billjk
  • 9,779
  • 22
  • 50
  • 72
  • 3
    Also, get rid of the silly and dangerous [`system("PAUSE");`](http://www.gidnetwork.com/b-61.html). – David Schwartz Feb 25 '12 at 23:44
  • 1
    How is it dangerous? Just wondering, and trying to learn more! – Billjk Feb 25 '12 at 23:53
  • 3
    It's dangerous because you don't know what `pause` is supposed to do. In Windows it works as wonders, but in Linux it's not defined and could be defined by someone else. I use it anyway for simple test programs because it does what it needs to in Windows and just gets ignored in Linux. – Mysticial Feb 26 '12 at 00:09
  • OK, thanks. What about on Mac? – Billjk Feb 26 '12 at 00:47
  • I've never programmed on a Mac so I wouldn't know... – Mysticial Feb 26 '12 at 01:46
  • 3
    Using system just for pausing? It is absurd! Use other functions like `getch`, `_getch`, `getchar`, `cin.getline`, or event `scanf` to wait for keyboard input! But in reality, you shouldn't use any of them. The program is finished, just leave it. – Ajay Feb 26 '12 at 09:37
  • Note that in C++ (and recent versions of C), it isn't necessary for `main` to `return 0`, as discussed [in this question](http://stackoverflow.com/questions/204476/what-should-main-return-in-c-c) - zero is returned by default. – James Feb 27 '12 at 13:33

10 Answers10

14
end1

should be:

endl

You used a 1 (the number) instead of l (the letter).

Mysticial
  • 452,826
  • 45
  • 327
  • 325
3

that’s endL just like end LINE :P

qdii
  • 11,918
  • 9
  • 56
  • 110
3

It should be endl (end line), not end1 (end one?):

cout << "Hello, World!" << endl;
cout << "Hooray!" << endl;
Andrejs Cainikovs
  • 25,695
  • 2
  • 70
  • 92
3

endl represent end line, it is not end1.

bitstore
  • 327
  • 2
  • 7
2

You have a typo. Try endl instead of end1.

Alex Reynolds
  • 94,180
  • 52
  • 233
  • 338
2

You should write endl instead of end1 (So make the one to a small "L")

FallenAngel
  • 17,186
  • 14
  • 82
  • 110
Marc
  • 257
  • 1
  • 7
2

It should be endl and not end1.

FallenAngel
  • 17,186
  • 14
  • 82
  • 110
NinjaCoder
  • 2,302
  • 3
  • 23
  • 45
0

replace end1 by endl and it'll work just fine! :)

  • Any particular reason why you answered this almost a year after the accepted answer which states exactly the same? – Bart Jan 12 '13 at 14:01
0

To avoid typos like the one you experienced, instead of using "endl", you can use 'new line' by inserting '/n' inside the quote.

Example:

cout << " Hi, this is how you do it /n"; 
Ebadly
  • 19
  • 5
0

You only need to replace your

     end1

with

    endl

Thus you have a syntax error that you need to fix by replacing the one('1') with an 'l', thereby fixing your program. It should compile and run successfully now.

Ruaan Volschenk
  • 717
  • 2
  • 11
  • 23