[ create a new paste ] login | about

Link: http://codepad.org/izr58431    [ raw code | fork ]

C++, pasted on Nov 11:
#include <iostream>
#include <fstream>
#include <limits>
std::ifstream f;
const std::streamsize MAXREAD = std::numeric_limits<std::streamsize>::max();

int main(int argc, char** argv) {
    if(argc < 2) {
        std::cerr << "Usage: wc [file]\n";
        return 1;
    }
    f.open(argv[1]);
    if(!f) {
        std::cerr << "Can't open file\n";
        return 1;
    }

    size_t popcount = 0;
    while(f.ignore(MAXREAD, '\n')) {
        popcount += (f.gcount() < MAXREAD);
    }

    std::cout << --popcount << '\n';
    return 0;
}


Create a new paste based on this one


Comments: