Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C++] Code Error

Legendary Battlemage
Joined
Feb 5, 2008
Messages
601
Reaction score
0
It says that it cant identify "end1" The code shows i need that there. I took out end1 and it booted the program, but not the "Hello World" Such a simple task.. Well heres the Code
PHP:
//needed to do stream input and output
#include <iostream>
//saves us from typing std::
using namespace std;

//Entry point for our application
int main()
{
    //prints Hello World to the screen
    cout<<"Hello World"<<end1;
    //waits to close consel
    system("PAUSE");
    //main must return a value.
    return 0;
}
 
Junior Spellweaver
Joined
Sep 16, 2006
Messages
187
Reaction score
0
Re: C++ Code Error

PHP:
#include <iostream>
#include "windows.h"

using namespace std;

int main()
{
	printf("Hello, World\n"); // \n = new line printf= like cout but i like printf :P
	cin.get(); // = press enter
}
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
What is wrong, is that you use end1 instead of endl. You use a 1 instead of a L (but then uncapitalised). It stands for endline, where only the first 4 characters are used ;), struggled with that too in the beginning ^^,

Anyways, I prefer getting rid of the 'using', and write it like this:

PHP:
#include <iostream>

int main(int argc, char *argv[])
{    
    std::cout << "Hello World!" << std::endl; // prints 'Hello World!' to the console
    system("PAUSE"); // waits for a key to be pressed (Windows only!)
    return 0;
}

You might say, why writing the std:: if you can use the 'using' keyword? This way my own code will never interfere with the 'std' code, so I don't have to worry so much. Also, this is more clear and everybody sees which function you want to use. Imagine you have a stream called 'cout'...which cout should it use?
 
Experienced Elementalist
Joined
Aug 25, 2005
Messages
253
Reaction score
20
When I started learning C++ 4 years ago, I used BorlandC as a compiler.

So this code was like:
Code:
#include <iostream.h>
#include <conio.h>

void main()
{
   cout<<"Hello world."<<endl;
   getch();
}

@Daevius, I don't know if it works with Visual Studio, but I assure you that with BorlandC will surely do work. :p
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
When I started learning C++ 4 years ago, I used BorlandC as a compiler.

So this code was like:
Code:
#include <iostream.h>
#include <conio.h>

void main()
{
   cout<<"Hello world."<<endl;
   getch();
}

You miss either 'using namespace std;' after the includes or 'std::' infront of every call to a function in the std namespace.

Visual Studio r0x

How does this help the original poster?
 
Back
Top