我是新的C++,我有這個代碼的麻煩的回報:試圖COUT功能
string output_date(int day, int month, int year){
string date;
if ((day > 0 && day <= 30) && (month > 0 && month <= 12) && (year >= 2013)){
switch (month){
case 1: date = day + " JAN " + year; break;
case 2: date = day + " FEB " + year; break;
case 3: date = day + " MAR " + year; break;
case 4: date = day + " APR " + year; break;
case 5: date = day + " MAY " + year; break;
case 6: date = day + " JUN " + year; break;
case 7: date = day + " JUL " + year; break;
case 8: date = day + " AUG " + year; break;
case 9: date = day + " SEP " + year; break;
case 10: date = day + " OCT " + year; break;
case 11: date = day + " NOV " + year; break;
case 12: date = day + " DEC " + year; break;
}
}
return date;
}
當我嘗試這樣做:
cout << output_date(22,12,2013);
沒有出現。我究竟做錯了什麼?
您的簽名中的函數名稱和調用位置不匹配。這是一個錯字,還是問題? – ajp15243
'「JAN」'不是'std :: string',所以添加的是指針添加。 '日+「JAN」+ year'是一個'const char *'指向誰知道的地方。 –
SSCCE對於這些類型的問題是最佳的。 – chris