. Advertisement .
..3..
. Advertisement .
..4..
I am trying to write a cpp that returns an invalid answer. I don’t know where the incorrect command is in the “cout is not a member of std”. My detail is:
#include <iostream>
#include "add.h"
int main()
{
int x = readNumber();
int y = readNumber();
writeAnswer(x + y);
return(0);
}
int readNumber()
{
int x;
std::cout << "Number: ";
std::cin >> x;
return x;
}
void writeAnswer(int x)
{
std::cout << "Answer: ";
std::cout << x;
}
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
int readNumber();
void writeAnswer(int x);
#endif // #ifndef ADD_H_INCLUDED
and I end up with the warning message:
error: ‘cout’ is not a member of ‘std’
Pls, suggest the best answer to fix it.
The cause:
The start of
io.cpp
is missing#include <iostream>
, so the error happens.Solution:
You can solve this problem by adding
#include <iostream>
to the start ofio.cpp
If you are using the zmq library, another way to solve this error is adding an extra entry in
cmake
to include the files and the included libraries also need to be added this.Remember that it must be:
It’s not the other way around