How to make cout not printing on the console.
Where do you want it to output character?
main() returns an int, always.
int main()
{
cout<<"Hello world"<<endl;
}
I'll just rewrite that example to make sure you
start correctly.
# include <iostream>
int main()
{
std::cout << "Hello world" << std::endl;
}
Is there any way where i can block printing on
console even when iam cout in my code..I mean even
using cout<<"Hello world"<<endl;. This is
shouldnt get printed on console..
Where should it get printed? If it's another
stream, many have pointed the std::ios::rdbuf()
solution. If it's to another graphical mean such a a
graphical window or whatever, you will have to use
operating-system-dependent functions.
If you want to completely "block printing on
console", do something like
# include <iostream>
template <
class char_t,
class traits = std::char_traits<char_t> >
class null_outbuf
: public std::basic_streambuf<char_t, traits>
{
protected:
virtual int_type overflow(int_type c)
{
// noop
return traits::not_eof(c);
}
};
int main()
{
null_outbuf<char> no;
std::cout << "hello";
std::streambuf *old = std::cout.rdbuf(&no);
std::cout << "this is not printed";
std::cout.rdbuf(old);
std::cout << "I'm back";
}