只是學習C++,所以我可能沒有正確理解這一點,但我只讀了範圍插入函數返回一個迭代器在新標準下(C++ Primer 5th Ed,cplusplus.com,cppreference.com,以及各種答案,建議使用它保持迭代器有效性)。STL容器的範圍插入函數在C++ 11下返回void?
從cppreference.com:
template< class InputIt >
iterator insert(const_iterator pos, InputIt first, InputIt last);
使用-std = C++ 11然而,Cygwin的GCC和MinGW的每一個版本,我試過返回無效。即使看看頭文件,它看起來就是這樣寫的,而且沒有什麼我可以修改來解決這個問題。
我錯過了什麼?
下面是我試圖編寫的'章節練習結束'功能;對更換一個字符串給定的字符串中:
(我理解爲意它的編寫方式也不起作用)
void myfun(std::string& str, const std::string& oldStr, const std::string& newStr)
{
auto cur = str.begin();
while (cur != str.end())
{
auto temp = cur;
auto oldCur = oldStr.begin();
while (temp != str.end() && *oldCur == *temp)
{
++oldCur;
++temp;
if (oldCur == oldStr.end())
{
cur = str.erase(cur, temp);
// Here we go. The problem spot!!!
cur = str.insert(cur, newStr.begin(), newStr.end());
break;
}
}
++cur;
}
}
?請不要說*「每個版本」*。這沒有幫助。請明確點。 – Nawaz 2013-04-11 04:11:41
啊,謝謝。最新版本使用mingw-get-inst-20120426.exe,4.6.2; i686的-W64-的mingw32-GCC-dw2-4.8.0-win32_rubenvb; x86_64的-W64-的mingw32-GCC-4.6.3-2釋放,win64_rubenvb;和MinGW-TDM 4.7.1-dw2 – Habnab 2013-04-11 04:20:52
試試。 GCC'4.8.0'。這是最新的! – Nawaz 2013-04-11 04:22:15