//为了方便,要包含的文件会不同,但我没有删 #include <iostream> #include <string> #include <vector> #include <bitset> #include <cstring> //和C语言的string.h其实是一个版本 #include <stdexcept> //或用 #include <exception> 都行 using std::bitset; using std::vector; using std::cin; using std::endl; using std::cout; using std::string; using std::overflow_error; //#define NDEBUG //--------------------------------------------------------------------------- string make_plural(size_t ctr,const string &word, const string &ending="s") { return (ctr==1)?word:word+ending; } int main(int argc,char **argv) { cout<<"success/tfailure/t"<<endl; cout<<make_plural(2,"success","es")<<"/t" <<make_plural(2,"failure")<<"/t"<<endl; return 0; } /* 219页习题7.26用字符‘s’为默认实参写函数make_plural,并输出failure和success的单数和复数形式 */