mercredi 19 octobre 2022

Can `>>` operator be overloaded to able to `std::cin >> function(with_param)` in C++?

I was wondering if it is possible if I can overload the >> operator?

For example in code. If I have this function that capitalize the first letter of std::string

auto capitalize_first_letter(std::string &text) -> void { 
  text[0] = toupper(text[0]); 
}

How can I do something like this

std::string word{};
std::cin >> capitalize_first_letter(word);

Is this possible?

Aucun commentaire:

Enregistrer un commentaire