我有这个简单的代码:
#include#include #include using namespace std; int main() { string s = "1,0"; string result; //result.resize(s.length()); replace_copy(s.begin(), s.end(), result.begin(), ',', '.'); cout << '"' << result << '"' << endl; cout << '"' << result.c_str() << '"' << endl; cout << result.length() << endl; return 0; }
result.resize
取消注释行的此程序的控制台输出是:
"1.0" "1.0" 3
-thats好的,但是当line with result.resize
被注释掉时,输出是:
"" "1.0" 0
- 这会导致奇怪的错误,因为result != result.c_str()
!!!
这种行为replace_copy
(以及可能也是类似的模板)可能会被视为标准库中的错误吗?我找不到任何与此主题相关的内容.谢谢.
编译器:mingw32-g ++ 4.7.1