Multiline ustring operations with Glib (in stream) (original) (raw)
September 13, 2024, 6:07am 1
Interesting, can I make same construction but, by using Glib
/ ustring
API?
#include <sstream>
std::istringstream stream(subject);
std::string line;
while (std::getline(stream, line)) {
std::cout<<line<<std::endl;
}
agpotter (Andrew Potter) September 14, 2024, 7:24pm 2
I guess you can do something like this:
std::locale::global(std::locale(""));
auto ustring_getline = [](std::istream& stream, Glib::ustring& uline) -> std::istream& {
std::string line;
std::getline(stream, line);
uline = Glib::locale_to_utf8(line); // may throw Glib::ConvertError
return stream;
};
for (Glib::ustring line; ustring_getline(std::cin, line);) {
std::cout << line << std::endl;
}
If you’re not actually dealing with system locale input you wouldn’t use Glib::locale_to_utf8() tho. If you know its utf8 you can simply uline = line
system (system) Closed October 14, 2024, 7:25pm 3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.