Solved

How do I output text to a text file?

Posted on 2011-03-07
3
293 Views
Last Modified: 2013-12-14
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
Comment
Question by:shaolinfunk
  • 2
3 Comments
 
LVL 1

Author Comment

by:shaolinfunk
ID: 35062117
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
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 35062236
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
 
LVL 1

Author Closing Comment

by:shaolinfunk
ID: 35063184
Hi JKR,

Works perfectly, thanks!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now