• Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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.

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
[edit] 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.exe
test123
Press any key to continue


- Drew

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement