CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: File input

  1. #1
    Join Date
    Sep 2001
    Posts
    30

    Question File input

    I need input into the file the string with size less than 64kb. What is the optimized way to do this?
    I use _write(...) function, no streams, but with streams is the so problem too. The problem is when I try to write string if file, sometimes programm writes more bytes in file, then in string is. More on 20. I dont imagine where may the error be. In number of written bytes I point strlen(my string). The string is dynamic chars array.

    Is anybody saw this problem?
    Thanks anymore

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    If you post your code which writes the string to the file, we might be able to see the problem more easily than if you just described it.
    Succinct is verbose for terse

  3. #3
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    The write function is very quick to blast memory to a file. If you're getting extra garbage in the file when you're done you might check two things..

    One are you openning the file in a mode which clears the previous contents of the file or are you adding to what's already there?

    Two when you specify how many bytes are going into the file are you dumping the size of the memory block? or are you dumping the string length. If you're dumping the memory block... say..

    char szBuffer[2048] = "blah blah blah";

    and you're saying something like sizeof(szBuffer);......

    Now if you want to get rid of that garbage then just use

    strlen(szBuffer) instead of sizeof...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured