[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1946
  • Last Modified:

Read CFile into CString

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
rkcth
Asked:
rkcth
  • 2
1 Solution
 
freshmeatCommented:
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
 
rkcthAuthor Commented:
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
 
freshmeatCommented:
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
 
CameronPCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now