SHARE
TWEET

Untitled

a guest Nov 19th, 2019 102 in 344 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <numeric>
  7.  
  8. int main()
  9. {
  10.     const std::string filename = "word.txt"; // I'm lazy
  11.     std::ifstream ifs(filename);
  12.     if (!ifs.good())
  13.     {
  14.         std::cout << "Something gone wrong with the file\n";
  15.         return 1;
  16.     }
  17.  
  18.     std::vector<int> chars_per_line, line_lengths;
  19.     std::string line;
  20.  
  21.     while (std::getline(ifs, line))
  22.     {
  23.         chars_per_line.emplace_back(std::accumulate(line.begin(), line.end(), 0, [](const auto & a, const auto & b){
  24.             return a + static_cast<int>(b != ' ');
  25.         }));
  26.         line_lengths.emplace_back(line.size());
  27.     }
  28.  
  29.     std::cout << "COLUMN" << std::setw(45) << "Number of Characters" << std::setw(41) << "Number of Blanks\n\n";
  30.     for (int i = 0; i < chars_per_line.size(); ++i)
  31.     {
  32.         std::cout << std::setw(3)  << i << std::setw(45) << chars_per_line[i] << std::setw(41) << (line_lengths[i] - chars_per_line[i]) << '\n';
  33.     }
  34.  
  35.     return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top