+ 3
Where is the problem ?
In class exactly cpp file Error:"cout " was not declared in this scope knowing that i used using namespace std
10 odpowiedzi
+ 3
On top of the beginning of your code add this-
#include <iostream>
Recommendation:-
Its better to use .
std::cout<<
Instead of using namespace std;
You just need to add "std::" in front if cout.
Note* Typing #include <iostream> is compulsory
+ 2
std::cout << "Whatever you were trying to print" << endl;
+ 2
Put the following code before int main():
using namespace std;
And you will be able to use cout.
For example:
#include<iostream> using namespace std; int main(){ char t = 'f'; char *t1; char **t2; cout<<t; return 0; }
Now take a moment and read up on what cout is and what is going on here: http://www.cplusplus.com/reference/iostream/cout/
Further, while its quick to do and it works, this is not exactly a good advice to simply add using namespace std; at the top of your code. For detailed correct approach, please read the answers to this related SO question.
+ 2
Shankhui Lunghar Of course it's not required, but his question implied that he wanted to write is as
cout << (EXPRESSION);
rather than substitute every time "cout" appears in his code for "std::cout".
Regarding your statement that "it will cause global confusion", what do you mean by "global"?
+ 1
Put this at the top of your file:
#include <iostream>
using std::cout;
(Please don't do "using namespace std;"; even though many programmers do it, it's considered to be bad practice, because if you have a variable, function, or type with the same name as a member of the namespace "std", your code won't compile)
0
Sapphire i am confident that "using" is not required,its just std::cout<<..........;
And also it will cause global collision.
0
Add "std::" before cout<<
- 2
#include "employee.h"
using namespace std;
void employee::setname(string n)
{
if(n.length()<3)
{
cout<<"name is too short\n";
}
else{
name=n;
}}
void employee::setage(int a)
{
age=a;
}
void employee::setsalary(double s)
{
salary=s;
}
string employee::getname()
{
if (name==" ")
{
return "not defined";
}
else {
return name;
}}
int employee::getage()
{return age;}
double employee::getsalary()
{
return salary;
}
employee::employee()
{
//ctor
}
employee::~employee()
{
//dtor
}