当我从boost运行此示例代码时
#!/usr/bin/perl
use strict;
use warnings;
# Get the results from "ip addr". Store in @results.
my @results = `ip addr`;
# Variable to store the previous line
my $prev_line;
foreach my $line (@results) {
# If the current line matches...
if ($line =~ m|link/ether|) {
# ... the extract the adapter name from the previous line
my ($adap) = $prev_line =~ /: (\w+):/;
print "$adap\n";
}
# Store the current line (which becomes the previous line).
$prev_line = $line;
}
我遇到这样的异常:#include <boost/locale.hpp>
#include <iostream>
using namespace std;
using namespace boost::locale;
int main()
{
generator gen;
// Specify location of dictionaries
gen.add_messages_path(".");
gen.add_messages_domain("foo");
// Generate locales and imbue them to iostream
locale::global(gen("pl_PL"));
cout.imbue(locale());
// Display a message using current system locale
cout << translate("Hello World") << endl;
}
仅当我在翻译中使用非ascii字符时才会出现问题。
我的std::runtime_error("Conversion failed")
文件中的示例内容(命令:.mo
)
msgunfmt foo.mo
答案 0 :(得分:3)
Boost抛出此异常,为什么要尝试转换翻译。
要解决此问题,只需将生成更改为:
msgid "Hello World"
msgstr "ąę"