C++primer plus第六版课后编程题答案8.1

8.1


#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string ;
void print(const string &s,int count=0);
static int number=0;//记录被调用的次数
void main81()
{
	print("I love you");
	print("Can you");
	print("haha",100);
	print("I love you");
	print("ooo",0);	//这里的第二个参数为0了
	print("Can you");
	print("lalala",50);
	system("pause");
}

void print(const string &s,int count)
{
	if(count==0)
		cout<<s<<endl;
	else 
		for(int i=0;i<number;i++)
			cout<<s<<endl;

	number++;//每调用一次++
}


posted @ 2014-04-10 13:46  天下纵横C++  阅读(243)  评论(0编辑  收藏  举报