Solved

Read CFile into CString

Posted on 2000-04-04
4
1,825 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Suggested Courses

738 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