CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Posts
    201

    Insert text to a file?

    Hello, all!

    How can I print some text into a .txt or .bat file?

    I use C++ with Virsual Studio 2008. I tryed on Google, those results in there didn't help...

    - realchamp.

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Smile Re: Insert text to a file?

    Here is an algorithm:

    1. Open a new file
    2. Copy the content of the old file into the new file up to the place where you want to insert your text
    3. Write your text to the new file
    4. Copy the rest of the old file to the new file
    5. Close the new file
    6. Remove the old file
    7. Rename the new file with the name of the old file

    Another algorithm is possible if the file is smaller than your available memory:

    1. Read the entire file into memory
    2. Write data from memory up to the place where you want to insert your text
    3. Write your text
    4. Write the end of your data from memory

  3. #3
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Insert text to a file?

    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  4. #4
    Join Date
    Feb 2009
    Posts
    201

    Re: Insert text to a file?

    Quote Originally Posted by Mybowlcut View Post
    Not like that. But I had some of the same pages.

  5. #5
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Insert text to a file?

    It's very convenient to become familiar with what terms to use. Good books will better your terminology.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

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