Redirecting cout to file
I don't consider this trivial. There a code sample you can look at here , but note that this connects a file descriptor that you write to to a stdin of a spawned process so you can pipe text into it , and likewise a file descriptor you read from to get the stdout of that process. You're doing a subset of the process: you're just redirecting stdout belonging to the current process. What I am not sure of is whether the file descriptor for stdout that you're redirecting will actuall affect the behavior of cout.
The content you requested has been removed. Ask a question. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. We use cookies to ensure you have the best browsing experience on our website. Start Your Coding Journey Now! Originally Posted by PadexArt. And to get meaningfull results in your log file you need to send wide data to the stream. The code above, if not included in a Unicode build, will not work as you expect.
July 27th, , AM 9. Re: Redirection of wcout Have you rebuilt your project? What Visual Studio are you using? July 27th, , AM Re: Redirection of wcout I'm so sorry, it's all right.
How careless I am. I'm sorry for my carelessness. Thank you! Re: Redirection of wcout Everyone here is so kind, I like here! July 28th, , AM Re: Redirection of wcout It apears a new problem. I want the program surport the local laguage, so I change the program to following. The whole concept of redirecting cout is a bad idea.
It will, for example, mean that if you call some other function in your code that wishes to write to cout for debug purposes, it goes to your file instead - which was probably not what you wanted. Do add out as the argument to CoolNumber recursive call, as otherwise the inner call will use cout as the output, which is probably not what you want. Or you could perhaps return a vector of strings from your function, and print them - following the principle of "do one thing, and do it well" - your current function mixes the calculation and the output, which is essentially doing two things.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 7 years, 2 months ago.
0コメント