Small File i/o Problem

This is a discussion on Small File i/o Problem within the C++ Programming forums, part of the General Programming Boards category; For some reason the function below clears my entire file. I don't know if getline() clears what it gets or ...

  1. #1
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40

    Small File i/o Problem

    For some reason the function below clears my entire file. I don't know if getline() clears what it gets or if something is wrong with my code. Either way, I need to figure out a way to count the lines without wiping out my file. Thanks!
    PHP Code:

    void lines
    (){

        
    File.open("data.txt",ios::in);

        if (
    File.is_open()){
            
            while(
    1){
                if (
    EOF == File.peek()){
                    break;
                }

                
    oflines++;
                
    File.getline(TempInLine256);

            }
        }
        
    File.close();
        

    - Grady (:

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    What data type is TempInLine? One solution is getline().

    std::getline(File, theString);

    Kuphryn

  3. #3
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    TempInLine is a char[256] and as far as I can tell, getline() is what I am using...
    - Grady (:

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    ios::in create a new file every time it's called.

    try ios::app if you want to keep adding to the file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. File i/o problem
    By tezcatlipooca in forum C++ Programming
    Replies: 18
    Last Post: 01-01-2007, 08:01 AM
  4. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21