【发布时间】:2017-11-09 18:41:59
【问题描述】:
我在用 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>’)"
这个错误来自我给你的函数中的 cout 行。
我在 linux Ubuntu 上使用 Geany 并使用 c++11。
感谢您的帮助
【问题讨论】:
-
我想你的意思是
std::endl -
你忘记了一封信。投票结束为错字。 (您书中的“endl”不是错字。只有丹麦人知道为什么会这样拼写。)
-
你在 main 里面也有函数定义——这是不对的
-
@pm100:这些声明非常接近最令人头疼的解析。
annee和jour被声明为整数,它们使用括号中的函数调用结果进行初始化。编辑:Demo -
@molbdnilo --
endl是 end of line 的缩写,就像ends它是 end of string 的缩写一样。跨度>