Error

This topic is 4759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I know this is dumb but i cant figure out whats wrong. I type this into VC++ 6 and get the error : error C2065: 'endl' : undeclared identifier. #include <iostream> int main() { int x = 5; int y = 7; std::cout << endl; std::cout << x + y << " " << x * y; std::cout << endl; return 0; } Any help for a noob C++ programer.

use std::endl

Share on other sites
using namespace std;

- Drew

Share on other sites
Still not working typed
#include <iostream>

using namspace std;

int main()
{
int x = 5;
int y = 7;
std::endl;
std::cout << x + y << " " << x * y;
std::endl;
return 0;
}

Share on other sites
Actually, I meant

#include <iostream>int main(){int x = 5;int y = 7;std::cout << std::endl;std::cout << x + y << " " << x * y;std::cout << std::endl;return 0;}

Share on other sites
Or, you could just use Drew_Benton's suggestion and get rid of all the "std::" things.

Share on other sites
I would also like to point out that if you use KrazeIke's post, it will work as is without the namespace I mentioned after him.

This works fine for me in VS6 -
#include <iostream>int main(){	int x = 5;	int y = 7;	std::cout << std::endl;	std::cout << x + y << " " << x * y;	std::cout << std::endl;	return 0;}

#include <iostream>using namespace std;int main(int argc, char* argv[]){	int x = 5;	int y = 7;	cout << endl << x + y << " " << x * y << endl;	return 0;}

That is an alternative though.

- Drew

Share on other sites
Hey thanks both codes work great. BTW im actaully using VS6 too but with just VC++ 6 installed.

Share on other sites
Hey Drew why di u put in the (int argc, char* argv[]) thing what does it do.

Share on other sites
The command line arguments are passed through those parameters.

Share on other sites
 KrazeIke, how do you beat me everytime [smile] [/edit]

That is the standard definition of the main function. It is not required like that because you are allowed to override it as you have, or you can make it "void main()".

Basically what happens is that those are the parameters send to the program. If you do this -
cout << argv[0] << endl;

You will see the path of the executable you are making. Bassically you can use it to allow a command line interface to your program.

'argc' is the number of items in 'argv', which is an array of the commands.

For a little more demo go to: "Project->Settings->Debug" and add in "Test123" to the Arguments edit box. Now type this in the code:
cout << argv[1] << endl;

You should now see:
G:\Visual Studio 6 Projects\test\Debug\test.exetest123Press any key to continue

- Drew

Short posts.

Share on other sites
Oh ok i see now thanks.