Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <regex>
- #include <streambuf>
- #include <Windows.h>
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //Console address to change text color
- /*
- Printing color messages in console
- Usage: print_str(sring_you_want_to_print, color_of_text, time_between_letters);
- Colors: https://i.stack.imgur.com/ZG625.png
- */
- inline bool print_str(std::string str, int k, int n)
- {
- SetConsoleTextAttribute(hConsole, k);
- for (int l = 0; l < int(str.size()); l++)
- {
- std::cout << str[l];
- Sleep(n);
- }
- SetConsoleTextAttribute(hConsole, 14);
- return true;
- }
- /*
- * Searches words for current assignment
- */
- void word_search(std::string& input, std::vector<std::string>& vec)
- {
- int count[32];
- memset(count, 0, sizeof count);
- std::string word = "";
- bool err = false, correct = false;
- for (unsigned int i = 0; i < input.length(); i++)
- {
- word.push_back(input[i]);
- if (strchr("аоуыиеёэюяАОУЫИЕЁЭЮЯ", input[i]) && ++count[input[i] & 31] > 1)
- correct = true;
- if ((input[i] == ' ' || input[i] == '\n' || i+1 == input.length()) && correct)
- {
- if (!err)
- {
- word.pop_back();
- vec.push_back(word);
- }
- memset(count, 0, sizeof count);
- correct = false;
- word = "";
- err = false;
- }
- if (!(input[i] >= 'а' && input[i] <= 'я' || input[i] >= 'А' && input[i] <= 'Я'))
- err = true;
- if (input[i] == ' ' && !correct)
- {
- memset(count, 0, sizeof count);
- correct = false;
- word = "";
- err = false;
- }
- }
- }
- /*
- * Read function, reads from given path/.../file
- * Usage: read(vec_you_want_to_fill)
- * Now automatically reads everything and fills linked string to further work
- */
- void read(std::string& file)
- {
- std::ifstream in;
- std::string file_path;
- print_str("Write file name or path to it: ", 10, 10);
- do {
- getline(std::cin, file_path);
- if (file_path.length() > 256)
- {
- print_str("You wrote too long file path and i ", 4, 10);
- file_path = "";
- }
- in.open(file_path);
- } while (!in.is_open() && print_str("Couldn't read the file, type again: ", 4, 10));
- file.assign((std::istreambuf_iterator<char>(in)),
- std::istreambuf_iterator<char>());
- in.close();
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- std::vector<std::string> words;
- std::string file;
- read(file);
- print_str("Content in file: \"", 11, 5);
- std::cout << file;
- std::ofstream out("out.txt");
- word_search(file, words);
- print_str("\"\nCorrect words: {", 11, 5);
- out << "Correct words: {";
- for (int i = 0; i < words.size(); i++)
- {
- std::cout << ' ' << words[i]; out << ' ' << words[i] << ',';
- print_str(",", 11, 5);
- }
- out << "}";
- out.close();
- print_str("\b }\n\nData was written in file in: \"C:\\Users\\Mike\\source\\repos\\ProgLang3 v21\\ProgLang3 v21\\ out.txt\"", 13, 5);
- print_str("\nPress enter to continue. . .", 7, 5);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement