Answer the question
In order to leave comments, you need to log in
C++ Clarify what's going on. How it works?
The whole code counts how many characters per line are entered by the user
#include <iostream>
#include <string>
#include <set> // ----><b> Что это ?</b>
using namespace std;
int main() {
setlocale(0, ""); // Локализация консоли
string text;
cout << "Наберите текст..." << endl;
cin >> text;
set<char> c(text.begin(), text.end()); // ----><b> очень Подробно здесь</b>
int col = c.size(); // ----> <b>очень Подробно здесь тк "c" даже не переменная(не объявлена)</b>
cout << "Различных символов в строке: " << col << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
The whole code counts how many characters per line are entered by the user
set<char> c(text.begin(), text.end()); // (std::)set<char> -- это множество (без повторений) символов.
// с -- это имя переменной.
// Конструктор множества с двумя итераторами добавляет во множество
// все объекты между этими итераторами. Т.е. все буквы из строки text.
int col = c.size(); // про c -- см. выше. std::set::size возвращает размер множества.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question