how do i get output which would normally appear on the screen, as in the Microsoft visual studio command prompt, written to a file such as a simple text file. say << X << is the output, what do i do from here? thanks
pjh-10 0 Light Poster
Recommended Answers
Jump to Post— Labdabeta 182You could use an fstream object. Here is a nice wrapper class to act exactly like cout except it goes to screen and file:
class fcoutstream { private: fstream file; public: fcoutstream(const char *fname){file.open(fname);} ~fcoutstream(){file.close();} template <typename T> fcoutstream &operator<<(const T& t) { cout<<t; file<<t; return *this; …
Jump to Post— Labdabeta 182also how do you do the code part, instead of pasting here?
This is an easy one just hit ENTER twice so that you have 2 blank lines. Now paste your code on the bottom one, then select all the code and hit TAB once.
As for file …
Jump to Post— triumphost 120FILE *stream ; //Redirect Output from console to a TextFile
if((stream = freopen("C:\Somefile.txt", "w", stdout)) == NULL)stream = freopen("CON", "w", stdout); //Redirect Output to the Screen
All 12 Replies
Labdabeta 182 Posting Pro in Training Featured Poster
pjh-10 0 Light Poster
Labdabeta 182 Posting Pro in Training Featured Poster
pjh-10 0 Light Poster
pjh-10 0 Light Poster
triumphost 120 Posting Whiz
pjh-10 0 Light Poster
pjh-10 0 Light Poster
triumphost 120 Posting Whiz
pjh-10 0 Light Poster
pjh-10 0 Light Poster
BobS0327 24 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.