本文主要是介绍函数声明--默认实参,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <iostream>
#include <string>
using namespace std;string make_plural(size_t ctr,const string &word,const string &ending ="s")//默认实参
{return (ctr==1)?word:word+ending;
}int main()
{cout<<"Singular version: "<<make_plural(1,"success","es")//success单数<<"\tplural version: "<<make_plural(0,"success","es")<<endl //success复数<<"Singular version: "<<make_plural(1,"failure") //failure单数<<"\tplural version: "<<make_plural(0,"failure")<<endl; //failure复数return 0;
}
这篇关于函数声明--默认实参的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!