C++/VC++ alternatives for PHP's SplFileObject class

114 views Asked by At

Is there any hand coded class or VC++ plugin available that is same as PHP's SplFileObject?

Please see the question https://stackoverflow.com/questions/10650864/fetching-nth-line-of-a-file/10650864#10650864. I want to achieve this using C++

1

There are 1 answers

1
Paulo Pinto On BEST ANSWER

Not sure why you want to use it for, what about iostreams or boost::filesystem?

http://msdn.microsoft.com/de-de/library/22z6066f%28v=vs.100%29

http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/index.htm

Update (adding a code example after reading the comments):

Something like this then?

#include <iostream>
#include <fstream>
#include <string>

int main(int argc, char* argv[])
{
    auto fd = std::fstream("veryLargeFile.txt");
    if (fd.good()) {
        std::string buffer;
        fd.seekg(200000);
        std::getline(fd, buffer);
        std::cout << buffer << std::endl;
    }
    fd.close();

    return 0;
}