开发者

Can't output through std::cout from static library

开发者 https://www.devze.com 2023-02-11 12:18 出处:网络
I\'m linking a static library that has a std::cout wrapper that works 开发者_Go百科if I use it from the application code, but non of the library\'s internal outputs (used in exactly the same fashion)

I'm linking a static library that has a std::cout wrapper that works 开发者_Go百科if I use it from the application code, but non of the library's internal outputs (used in exactly the same fashion) show any output.

Maybe it's not important, but I'm using Qt Creator and qmake project files to build. I have added console to the application's CONFIG (and even tried that for the static library, but it had no effect).

What could be going wrong and how can I fix this? Thanks!

UPDATE: well, the wrapper is an adapted version of this one:


The std::cout wrapper won't be able to 'reach in' to another library implicitly. Have you thought about redirecting cout altogether? Something likesrc:

int main() { 
    std::streambuf* cout_sbuf = std::cout.rdbuf(); // save original sbuf 
    std::ofstream   fout("cout.txt"); 
    std::cout.rdbuf(fout.rdbuf()); // redirect 'cout' to a 'fout' 
    // ... 
    std::cout.rdbuf(cout_sbuf); // restore the original stream buffer 
}

That way you'd have control over data fed to std::cout, regardless of the library doing the output (unless, of course, they redirect std::cout themselves.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号