c++ - std::collate::transform caused segmentation fault -
When I run the following source code, "Segmentation fault (core dump)" is found on line # 3
char s [] = "helloworld"; Const std :: collate & lt; Char & gt; * PC = & amp; Std :: use_facet & lt; Std :: collate & lt; Char & gt; & Gt; (Std :: location ("en_US")); Std :: string str = pc- & gt; Result (s, s + std :: strlen (s)); Std :: cout & lt; & Lt; Str.length () & lt; & Lt; "," & Lt; & Lt; Str & lt; & Lt; Std :: endl; If I line # 2 to
const std :: collate & lt; Char & gt; * Pc = new std :: collate_byname & lt; Char & gt; ("En_US"); I can get the right result. I think the result of this two line should be the same, they all meet together with the performance environment, so why did one mistake in the past? Did I do something wrong?
PS: C ++ Compiler G ++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3).
Reading:
The references given by this function to any < The code> std :: locale object exists which implements the mask.
You are creating a temporary std :: locale in your code, so that the expression expires temporarily, and you have left with a glance indicator Like, it should work: char s [] = "helloworld"; Std :: locale en_US ("en_US"); Const std :: collate & lt; Char & gt; * PC = & amp; Std :: use_facet & lt; Std :: collate & lt; Char & gt; & Gt; (At hi); Std :: string str = pc- & gt; Result (s, s + std :: strlen (s)); Std :: cout & lt; & Lt; Str.length () & lt; & Lt; "," & Lt; & Lt; Str & lt; & Lt; Std :: endl;
Comments
Post a Comment