Solved

How do I output text to a text file?

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

730 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