parallel-programming/3/system/windows/Parallel32.cpp

78 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Parallel32.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <experimental/filesystem>
using namespace std::experimental::filesystem::v1;
void countFileStats(const std::string& filePath) {
std::ifstream file(filePath);
if (!file.is_open()) {
std::cerr << "Unable to open file: " << filePath << std::endl;
return;
}
std::string line;
int lineCount = 0;
int wordCount = 0;
int charCount = 0;
while (std::getline(file, line)) {
lineCount++;
charCount += line.length();
// Count words in the line
bool inWord = false;
for (char c : line) {
if (std::isalpha(c)) {
if (!inWord) {
inWord = true;
wordCount++;
}
}
else {
inWord = false;
}
}
}
std::cout << "File: " << filePath << std::endl;
std::cout << "Number of lines: " << lineCount << std::endl;
std::cout << "Number of words: " << wordCount << std::endl;
std::cout << "Number of characters: " << charCount << std::endl;
file.close();
}
int main(int argc, char* argv[]) {
int count = 0;
int ver = std::atoi(argv[1]) * 125;
int cborder = 125;
if (std::atoi(argv[2]) == 1) {
cborder = 126;
}
while (count < cborder) {
std::string directoryPath = "C:\\Dod\\Dod1\\" + std::to_string(ver + count) + ".txt";
countFileStats(directoryPath);
count++;
}
system("pause");
return 0;
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
// Советы по началу работы
// 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
// 2. В окне Team Explorer можно подключиться к системе управления версиями.
// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
// 4. В окне "Список ошибок" можно просматривать ошибки.
// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.