Thread: reading a file with getline and skipping lines..

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    14

    reading a file with getline and skipping lines..

    I don't understand why it's not working.. I've made programs using the same syntax and I haven't had any problems but now for some reason its skipping lines. To be specific: its skipping the first, reading the second, skipping the third and so on.

    Code:
    void LoadRegistry()
    {
    
        ifstream reg ("Registry.txt");
        string line, s1, s2;
        size_t pos;
    
            if (reg.is_open())
            {
            while ( reg.good() )
                {
                getline (reg, line);
                if (line != "")
                    {
                        getline(reg, line);
                        pos = line.find(string1);
                        s1 = line.substr(0, pos);
                         }
                    }
    
                }
        }
    I copied the code into a new program and ran it and it worked awesome. But when it's in the original program that has a lot of voids and I'm only running this one and its not working. Did anybody have this problem as well? I just don't understand. Any help is much appreciated.

    Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
               getline (reg, line);
                if (line != "")
                    {
                        getline(reg, line);
    line 1
    line 2
    line 3
    line 4
    etc.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    14
    -_-

    Wow. Thanks. I guess I should proofread everything I copy and paste on a program. Lol.
    Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. skipping lines with an input text file
    By kwikness in forum C++ Programming
    Replies: 7
    Last Post: 12-12-2006, 09:11 AM