[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1984
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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