簡體   English   中英

錯誤 C2661 'fmt::v7::print': 沒有重載 function 需要 3 個 arguments

[英]Error C2661 'fmt::v7::print': no overloaded function takes 3 arguments

我正在嘗試做:

fmt::print(fg(fmt::color::red), "A critical error has occured. consult the logs and fix the issue! {0}", std::endl);

這會導致錯誤消息: Error C2661 'fmt::v7::print': no overloaded function takes 3 arguments

查看 此處的官方文檔將fmt::print顯示為:

 template <typename S, typename... Args>
void fmt::print(const text_style &ts, const S &format_str, const Args&... args)

這表明 arguments 的數量不應該是一個問題,事實上,它不是。 如果我用像1這樣隨機的東西替換std::endl ,它編譯和構建就好了嗎? 這里有什么問題?

std::endl是一個模板,但在這種情況下無法確定模板 arguments,您必須明確指定它們。 例如

fmt::print(fg(fmt::color::red), 
           "A critical error has occured. consult the logs and fix the issue! {0}", 
           std::endl<char, std::char_traits<char>>);
//                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

該錯誤消息在技術上是不正確的,因為fmt::print過載需要 3 個 arguments。 但是,即使您能夠傳遞std::endl ,這也沒有意義,因為刷新將應用於中間緩沖區,而不是在寫入stdout時。 您應該使用\n並改為調用fflush

fmt::print(fg(fmt::color::red),
           "A critical error has occured. consult the logs and fix the issue!\n");
fflush(stdout);

請注意,顯式傳遞模板 arguments 將不起作用 - 您只會得到一個不同的錯誤: https://godbolt.org/z/T3GYqdchb

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM