c – 為什麼我不能在vector中放置ifstream?
以下示例程式也不為我編譯
cl ang 3.1或gcc 4.8:
#include <fstream> #include <vector> using namespace std; int main() { vector<ifstream> bla; bla.emplace_back("filename"); return 0; }
不過,我以為emplace_back應該是
“Insert a new element at the end of the vector, right after itscurrent last element. This new element is constructed in place usingargs as the arguments for its construction.”
有誰知道為什麼這不編譯呢?我誤解了還是圖書館的實施還沒有完成?
c 11中的流是可移動的,所以在理論上你應該能夠做你想要的,問題是可移動流還沒有在gcc / libstdc中實現.
要進一步備份我的答案,請看看gcc / libstdc c 11狀態:
ofollow,noindex" target="_blank">http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011特別是27.5,27.8,27.9
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/17089584/why-cant-i-emplace-ifstreams-in-a-vector