Solved

Read CFile into CString

Posted on 2000-04-04
4
1,756 Views
Last Modified: 2013-11-20
I need a file in CString format. I am using CFile. Could someone please tell me how to get the information stored in the CFile into a CString.
Thanks,
Sincerely Robert
0
Comment
Question by:rkcth
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
freshmeat earned 50 total points
ID: 2686115
only read the file into a CString:
use CFile::Read(), CFile::Seek()
for example:

char      szBuffer[256];
UINT      nActual = 0;
CFile myFile;
CString myString;

myFile.Seek( 0, CFile::begin );
nActual = myFile.Read( szBuffer, sizeof( szBuffer ) );
myString=szBuffer;

hope it will help u!
0
 

Author Comment

by:rkcth
ID: 2689228
Well actually I can do it with a buffer, I want to do it without having to repeat the read process several times with my buffer. I guess it is not possible?
0
 
LVL 2

Expert Comment

by:freshmeat
ID: 2691933
then you may set the buffer large enough, such as:

char szBuffer[myFile.Length]

thank u for ur points, that is what i like
^@^
0
 

Expert Comment

by:CameronP
ID: 5679145
freshmeat,

char szBuffer[myFile.Length]

Have you actually tried this code?  I do not believe this code will work.  You cannot create an array dynamically like you're trying to.  How else would you do this?

I actually have the same problem, but also do not wish to repeated read the file and add it to the string.

Cheers,
Cameron
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

747 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

10 Experts available now in Live!

Get 1:1 Help Now