std::messag...ges::do_get(3)
π std::messag...ges::do_get(3) π
okay bestie so this little page lives in the C++ Standard Libary manual and it's all about std::messages::get and std::messages::do_get β the message-catalog girlies. i18n slay, no cap β¨
πΈ NAME πΈ
std::messages::get, std::messages::do_get β literally the exact same two names, that's the whole NAME section, we move π
std::messages::get, std::messages::do_get
β¨ Synopsis β¨
Defined in header <locale>, bestie:
public:
string_type get( catalog cat, int set, int msgid, const string_type&
dfault ) (1)
const;
protected:
virtual string_type do_get( catalog cat, int set, int msgid, const
string_type& (2)
dfault ) const;
- the public member function β it just calls the protected virtual member function
do_getof the most derived class π«Ά - the actual worker β it obtains a message from the open message catalog
cat, using the valuesset,msgidanddfaultin an implementation-defined manner. and if the expected message is not found in the catalog, it returns a copy ofdfault. periodt π
π¦ Parameters π¦
catβ identifier of message catalog obtained fromopen()and not yet passed toclose()π (do not be messy about this)setβ implementation-defined argument, message set in POSIXmsgidβ implementation-defined argument, message id in POSIXdfaultβ the string to look up in the catalog (if the catalog uses string look-up) and also the string to return in case of a failure. she's doing double duty, main character energy fr fr π
π Return value π
The message from the catalog, or a copy of dfault if none was found. simple as that π
π Notes π
On POSIX systems, this function call usually translates to a call to catgets(), and the parameters set, msgid, and dfault are passed to catgets() as-is. iconic, no notes π
In GNU libstdc++, this function ignores set and msgid and simply calls GNU gettext(dfault) in the required locale. the way that it just does its own thing ππ
π§ Example π§
The following example demonstrated retrieval of messages: on a typical GNU/Linux system it reads from /usr/share/locale/de/LC_MESSAGES/sed.mo. lowkey obsessed with how specific that is π
// Run this code
#include <iostream>
#include <locale>
int main()
{
std::locale loc("de_DE.utf8");
std::cout.imbue(loc);
auto& facet = std::use_facet<std::messages<char>>(loc);
auto cat = facet.open("sed", loc);
if (cat < 0)
std::cout << "Could not open german \"sed\" message catalog\n";
else
std::cout << "\"No match\" in German: "
<< facet.get(cat, 0, 0, "No match") << '\n'
<< "\"Memory exhausted\" in German: "
<< facet.get(cat, 0, 0, "Memory exhausted") << '\n';
facet.close(cat);
}
Possible output:
"No match" in German: Keine Γbereinstimmung
"Memory exhausted" in German: Speicher erschΓΆpft
she ate that π½οΈπ₯
β See also β
ngl this section as printed doesn't list any cross-reference entries β it's giving empty, but we're keeping the heading because we keep everything, iykyk ππ
and that's the whole page, bestie π«Ά β brought to you by http://cppreference.com, edition 2024.06.10, filed under std::messag...ges::do_get(3). go read a message catalog, ily πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms