I am redirecting my standard output data to a std::ofstream buffer, to write the data in a file. The following code implement this,
if ( isActive ){
try{
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
std::cout<<"buffer pointed\n"<<std::endl;
}
when i am implementing the above code in a single .cpp, itgeting executed and dada is geting write in the file.But for the following scenarion,
A( bool isActive){
if ( isActive ){
try{
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
std::cout<<"buffer pointed\n"<<std::endl;
}
And from a different .cpp the function A( true ) is getting called, and I want that after A() called then in my whole c++ project when ever std::cout<"printing data\n"; is there the data will be printed into the file. But my code is compiling fine, during RUN time throwing the following error,
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. QGtkStyle was unable to detect the current GTK+ theme. Qt: Session management error: None of the authentication protocols specified are supported
But if I am placing the following code at main,
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
the run time all the std::cout data is geting write in the file. ut throwing the following error. How can I solve this error.
enter code here(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. QGtkStyle was unable to detect the current GTK+ theme. Qt: Session management error: None of the authentication protocols specified are supported
cout
is never restored to its original state before this happens and is using a buffer that no longer exists since theostream
also gets destroyed. This is the only thing I can think of atm.. – Brandon