How to save CStrings to a file? 
Author Message
 How to save CStrings to a file?

CString goodinput;
int i;
// CFile fileA // already opened
 i=  goodinput.GetLength();
....
fileA.Write(goodinput, i );
....
This *almost works*.  The problem is that there are spaces
inserted between the characters.  Is there a way to
convert the CString to normal string (char buffer[1000] )
that actually works?
I tried with
char pbuf[100];
strcpy(pbuf,(CHAR *)(goodinput.GetBuffer
(goodinput.GetLength())));
 fileA.Write(pbufDS, i );
but the file just gets garbage.

Adam

Quote:
>-----Original Message-----
>Hi,

>how can I save one or more CStrings to a file and read
>them again? The problem is that when you try to read a
>CString the size of this string is unknown. I just want
to
>write a text file out of these CStrings. Any suggestions
>on this topic? thank you.
>.



Tue, 08 Feb 2005 23:30:31 GMT  
 How to save CStrings to a file?
This is how I do it...  I'm sure there is a better way though...

 CString TV = szString;
 char *wTV = new char[TV.GetLength()];
 for (int x = 0; x < TV.GetLength(); x++)
 {
  wTV[x] = char(TV.GetAt(x));
 }
 int i = TV.GetLength();
 bSuccess = WriteFile(hFile, wTV, i, &numWrite, NULL);

--
---------------------------------
Bryan
Take the World's Smallest Political Quiz
http://www.self-gov.org/wspq.html


Quote:
> CString goodinput;
> int i;
> // CFile fileA // already opened
>  i=  goodinput.GetLength();
> ....
> fileA.Write(goodinput, i );
> ....
> This *almost works*.  The problem is that there are spaces
> inserted between the characters.  Is there a way to
> convert the CString to normal string (char buffer[1000] )
> that actually works?
> I tried with
> char pbuf[100];
> strcpy(pbuf,(CHAR *)(goodinput.GetBuffer
> (goodinput.GetLength())));
>  fileA.Write(pbufDS, i );
> but the file just gets garbage.

> Adam

> >-----Original Message-----
> >Hi,

> >how can I save one or more CStrings to a file and read
> >them again? The problem is that when you try to read a
> >CString the size of this string is unknown. I just want
> to
> >write a text file out of these CStrings. Any suggestions
> >on this topic? thank you.
> >.



Wed, 09 Feb 2005 01:35:16 GMT  
 How to save CStrings to a file?
Hi ,

First of all try to get rid of char from the code ,use TCHAR / WCHAR
instead .
Instead of strcpy( ) use wcscspy( ) .

Things should work as expected .

Best regards,
Satyen

Quote:

> CString goodinput;
> int i;
> // CFile fileA // already opened
>  i=  goodinput.GetLength();
> .....
> fileA.Write(goodinput, i );
> .....
> This *almost works*.  The problem is that there are spaces
> inserted between the characters.  Is there a way to
> convert the CString to normal string (char buffer[1000] )
> that actually works?
> I tried with
> char pbuf[100];
> strcpy(pbuf,(CHAR *)(goodinput.GetBuffer
> (goodinput.GetLength())));
>  fileA.Write(pbufDS, i );
> but the file just gets garbage.
> Adam
> >-----Original Message-----
> >Hi,

> >how can I save one or more CStrings to a file and read
> >them again? The problem is that when you try to read a
> >CString the size of this string is unknown. I just want
> to
> >write a text file out of these CStrings. Any suggestions
> >on this topic? thank you.
> >.



Fri, 18 Feb 2005 18:53:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to save CStrings to a file?

2. Save array of CStrings

3. Saving CStrings to Disk: Without using framwork File Save; HOW?????

4. Converting CStrings or Using Cstrings in switch()

5. Basic Open File, Save/ Save as functions for dos word processor

6. ! Saving (graphics) to file - saving window contents (PICT) in Code warrior C (on a Mac PPC)

7. How to obtain name of file on Save/Save As

8. How to obtain name of file on Save/Save As

9. File-level const CStrings cause memory leak?

10. How to download results file from form post (In IE it generates a save file dialog)

11. Reading file..Saving data in new file...

12. Binary file read to New text file save grief

 

 
Powered by phpBB® Forum Software