Solved

How do I output text to a text file?

Posted on 2011-03-07
3
289 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

706 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

23 Experts available now in Live!

Get 1:1 Help Now