G
G
GoodOrlov2018-10-19 22:57:19
C++ / C#
GoodOrlov, 2018-10-19 22:57:19

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

1 answer(s)
J
jcmvbkbc, 2018-10-19
@GoodOrlov

The whole code counts how many characters per line are entered by the user

How many different characters.
set<char> c(text.begin(), text.end()); // (std::)set<char> -- это множество (без повторений) символов.
                                       // с -- это имя переменной.
                                       // Конструктор множества с двумя итераторами добавляет во множество
                                       // все объекты между этими итераторами. Т.е. все буквы из строки text.
  int col = c.size();  // про c -- см. выше. std::set::size возвращает размер множества.

More about std::set .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question