<commit_before>#include <iostream>
#include <string>
#include <vector>
#include <fstream>


std::vector<int> count_lines_in_files(std::vector<std::string> const& files) {
    std::vector<int> results{};

    char c = 0;
    for (auto const& file : files) {
        int line_count{0};
        
        std::ifstream in{file};
        while (in.get(c)) 
            if ('\n' == c)
                line_count++;
        
        results.push_back(line_count);
    }

    return results;
}


int main() {
    for (auto const line_count : count_lines_in_files( { "main.cpp" }))
        std::cout << line_count << " line(s)\n";

    return 0;
}
<commit_msg>[i_cukic-fucn_progr_in_cpp][ch 01] slightly rewrite file line counting (in an imperative way)<commit_after>#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace test { // -> imperatively read from a file 

std::vector<int> countLines(std::vector<std::string> const& files) {
    std::vector<int> ret{};
    char c{0};

    for (auto const& file : files) {
        std::ifstream in{file};

        int lineCnt{0};
        while (in.get(c))
            if ('\n' == c)
                ++lineCnt;

        ret.push_back(lineCnt);
    }

    return ret;
}

void run() {
    for (auto const cnt : countLines({ "main.cpp", "main.cpp", "main.cpp" }))
        std::cout << "line count: " << cnt << std::endl;

}
} // test


int main() {
    std::cout << "test => [ok]" << std::endl; test::run(); std::cout << std::endl;

    return 0;
}

{'fraction_non_alphanumeric': 0.17019867549668874, 'fraction_numerical': 0.005298013245033113, 'mean_word_length': 2.6235011990407675, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5401500', 'n_tokens_mistral': 544, 'n_tokens_neox': 518, 'n_words': 126}