To rectify this problem, the standard namespace (abbreviated: std) was created to store objects like cout to be used for their desired purpose. As a result, developers can now use an object like cout to print a string but must point to it in the standard namespace.
There is no std::cout in C. In a windowing system, the std::cout may not be implemented because there are windows and the OS doesn't know which one of your windows to output to. never ever give cout NULL. it will stop to work.
As for why it is so "time consuming", (in other words, slow,) that's because the primary purpose of std::cout (and ultimately the operating system's standard output stream) is versatility, not performance.
You need to include
#include <string>
#include <iostream>
You need to reference the cout's namespace std
somehow. For instance, insert
using std::cout;
using std::endl;
on top of your function definition, or the file.
There are several problems with your code:
WordList
is not defined anywhere. You should define it before you use it.#include <string>
before you can use the string class and iostream before you use cout
or endl
.string
, cout
and endl
live in the std
namespace, so you can not access them without prefixing them with std::
unless you use the using
directive to bring them into scope first.Above answers are good but If you do not want to add string include, you can use the following
ostream& operator<<(ostream& os, string& msg)
{
os<<msg.c_str();
return os;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With