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

Thread: File I/O help

Threaded View

  1. #1
    Join Date
    Jul 2008
    Posts
    27

    File I/O help

    Hey everone,

    I recently decided to try programming in C++, and so far I have been doing very well on my own. However, I ran into a massive wall in the program I am trying to build: C++ file I/O functions. After weeks of experimenting and searching, I still can't figure out what I am doing. Hopefully someone can help.

    I need to read in 350 characters from file1 as a string, pass it to a function I created to modify the string (it takes in a string and returns a string), and then output the string to file2. This loops until file1 has been completely read in. Then, file2 needs to be read in the same way and output to file3.

    In psuedocode:
    Code:
    file1 = open "test.txt";
    file2 = open "test2.txt";
    
    string mystring
    
    while(!EOF file1){
        mystring = read 350 chars from file1;
        mystring = my_function(mystring);
        write mystring to file2;
    }
    
    close file1;
    close file2;
    
    file1 = open "test2.txt";
    file2 = open "test3.txt";
    
    while(!EOF file1){
        mystring = read 350 chars from file1;
        mystring = another_my_function(mystring);
        write mystring to file2;
    }
    
    close file1;
    close file2;
    Does that make sense?

    I can't use the getline function, because there are few new lines if any in the 100 MB file to be read in and changed, and I only want 350 characters at a time. Also, newlines and spaces need to be preserved.

    Thanks for your time,
    Jason
    Last edited by JasonBB; July 5th, 2008 at 11:56 AM.

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