:cry: I am very confused, i am working on a console application and it doesn't seem that my console output codes are working. Can someone tell me whats wrong?

cout << "text" << end1;

Recommended Answers

All 6 Replies

Surely your compiler is giving you a message? And endl is spelled with an l (ell) at the end, not a 1 (one).

THanks alot, sorry I'm still pretty new to C++ so im still workin on my basics the error that it is giving me is

6 C:\FirstProject\main.cpp `cout' undeclared (first use this function)

6 C:\FirstProject\main.cpp `endl' undeclared (first use this function)

C:\FirstProject\Makefile.win [Build Error] [main.o] Error 1

C:\FirstProject\main.cpp In function `int main(int, char**)':

Those are the errors I have gotten, and this is the basic code im working with

#include <iostream>
#include <stdlib.h>

int main(int argc, char *argv[])
{
cout << "text" << endl;
system("PAUSE");
return 0;
}

You are using functions from the std namespace without qualifying them. In your early learning stages, the simplest solution is to add the following after your #includes.

#include <iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
   cout << "text" << endl;
   system("PAUSE");
   return 0;
}

Please post code within CODE tags.

Thank you very much both of you i really appreciate it

the problem with the code is that because you have <iostream> and not <iostream.h>. <iostream> is a shorthand which only works if you say you are using the standard namespace (which allows shorthand re-naming) ie using namespace std; sorry had to clarify that :)
the problem is the conflict with <iostream> (no.h) and <stdlib.h> (a .h) which means the compiler cannot second guess the namespace for you, i think...?

Dave Sinkula --> could you have a look at c/c++ tutorials post "namespaces" as i have a post question in there about namespaces as there is something i am confused about and u seem to know a bit about it. cheers :)

As Dave mentioned

#include <iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
   cout << "text" << endl;
   system("PAUSE");
   return 0;
}

works. Just a reminder, system("PAUSE") activates the old DOS command PAUSE and is not very portable code. There is also a school of thought that claims that namespace std clutters things up for other potential namespaces.

So ...

#include <iostream>

int main()
{
   std::cout << "text" << endl;
   std::cin.get();  // wait
   return 0;
}

... would be another way to do your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.