c++ - 无法使用 std::end 打印字符串

标签 c++ linux c++11 ubuntu

<分区>

我在用 C++ 打印字符串时遇到问题。

我知道在 SO 上有很多关于这个问题的话题,但大多数人说要包括 <string> , <iostream>namespace std .但是我做了所有这些但仍然遇到问题。这是我的代码和错误。

#include <iostream>
#include <string>
using namespace std;
//...
void affiche_date(int annee, int nbjours) {
    string mois;
    if (nbjours>31) {
         mois = "avril";
         nbjours -= 31;
    } else {
        mois = "avril";
    }
    cout << "Date de Paques en " << annee << " : " << nbjours << " " << mois << end;
}

int main() {
    int annee ( demander_annee() ) ;
    int jour ( date_paques(annee) );
    affiche_date(annee, jour);
}

这是我在编译时遇到的错误:

"error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘<unresolved overloaded function type>’)" 

这个错误来 self 给你的函数中带有 cout 的行。

我在 Linux Ubuntu 上使用 Geany 并使用 c++11。

谢谢你的帮助

最佳答案

std::end()是一个将迭代器获取到容器末尾的函数。

您打算使用 std::endl改为使用流操纵器。

注意:避免在实际代码中使用 using namespace std;,要么利用 using 指令只引入您需要的内容,要么支持使用 namespace 限定名称,就像我在这里一样。

关于c++ - 无法使用 std::end 打印字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47209319/

相关文章:

c++ - 如何暂停进程中的所有线程(停止世界)

linux - 如何修复linux下编译错误

linux - 如何在 bash 脚本和 Matlab 之间传递变量

c++ - 除法和乘法 std::chrono::durations

C++ 共享库宏

c++ - 命名空间 std 符号干扰全局符号

c++ - bool 表达式作为模板参数

linux - 为什么我需要对 uniq 进行排序以删除重复行?

c++ - 枚举与强类型枚举

c++ - 开关盒错误 |的值在常量表达式中不可用