4
A
回答
9
是的。實際上,std::endl
是一個函數模板,它將作爲std::basic_ostream
模板的任何專門化操作符。
一些更詳細地:27.7.3.6規定,所述std::basic_ostream
模板包含過載operator<<
如下:
basic_ostream<charT, traits> &
operator<<(basic_ostream<charT, traits> (*pf)(basic_ostream<charT, traits> &));
在合適的函數調用此過載的效果是return pf(*this)
。所以當你說std::cout << std::endl
時,這實際上變成std::endl(std::cout)
並且返回對流對象的引用。
所有其他的ostream操縱器都以相同的方式編寫,對於輸入操縱器也是如此。
的endl
功能模板的魔術是widen('\n')
一個呼叫,它產生正確的「換行符」數據爲給定的字符類型。
相關問題
- 1. 什麼是std ::與cout和endl一起使用?
- 2. std :: cout和std :: wcout有什麼區別?
- 3. std :: cout << x;和std :: cout << x << std :: endl;?
- 4. Cout和endl錯誤
- 5. wcout和wcerr:如何讓它與unicode一起工作?
- 6. boost :: variant與std :: string一起工作嗎?
- 7. 一個std :: endl使三個std :: endl(s)?
- 8. 應該使用std :: endl嗎?
- 9. COUT怎樣的std ::工作
- 10. 有沒有人知道endl(cout)和cout << endl之間的區別?
- 11. std :: chrono和cout
- 12. 混合cout和wcout在同一個程序
- 13. 代碼只與endl一起工作 - 很奇怪
- 14. ENDL不與wstring的(Unicode)的工作
- 15. 符號endl和cout無法解析
- 16. 是否有一個統一的cout/wcout處理的char *和* WCHAR
- 17. weak_ptr與unique_ptr一起工作嗎?
- 18. wcout如何工作?
- 19. nohup和std :: ignore()不一起工作
- 20. 當extern「C」時不能使用cout/endl
- 21. 所屬類別名稱()和ENDL不要在Windows一起工作和MinGW
- 22. 在cout <<「hello」<< endl中刪除endl後,我的C++程序停止工作
- 23. std :: cout聲明如何工作?
- 24. std ::字符串不工作的cout
- 25. std :: cout不工作在for循環內
- 26. ASCII字符未打印在WCOUT和COUT中
- 27. cout緩衝區和C++中的endl的結構
- 28. 無法使用std :: getline()與ifstream和ofstream一起工作
- 29. C++ wcout的std ::地圖值
- 30. xcode std :: wcout用wchar_t或std :: wstring!
如何編寫代碼來測試它? – asheeshr
我認爲他的意思是問他用wcout使用endl是否有什麼問題。 – ctor
我添加了一些更詳細的解釋操縱器如何工作。 –