[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

How do I output text to a text file?

I am trying to debug a program. In order to this I want to output some text contained in a CString variable to c:\debug.txt.

I already have the debug message I want in CString "csMessage".  How do I output the contents of  csMessage to c:\debug.txt.  

Code that I can use would be much appreciated!
0
shaolinfunk
Asked:
shaolinfunk
  • 2
1 Solution
 
shaolinfunkAuthor Commented:
I forgot to add..c:\debug.txt does not exist yet.  How do I make it so that your function creates this file as well?  And if the file did already exist to just delete it and/or write over it?
0
 
jkrCommented:
Not a big problem - you can use an 'ofstream', which will overwrite the file when opening it, e.g.
#include <fstream>
#unsing namespace std;

//...

ofstream os("c:\\debug.txt");

CString csMessage = "Test";

os << (LPCTSTR) csMessage << endl;

os.close();

Open in new window

0
 
shaolinfunkAuthor Commented:
Hi JKR,

Works perfectly, thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now