C++PrimerCH6函数

在这里插入图片描述

#include<iostream>
#include<string>

#include <initializer_list>
using std::initializer_list;

using std::cin;
using std::cout;
using std::endl;
using std::string;

int test_static_value() {
	static size_t count = 0;
	return ++count;
}
int test_static_value2() {
	static size_t count;
	return count;
}

void change(string& s1, string* s2) {
	string temp = s1;
    s1 = *s2;
	*s2 = temp;
	return;
}
bool checkTopChar(const string& s) {
	for (auto& c : s) {
		if (isupper(c))
			return true;
	}
	return false;
}
string TurnLowChar(string& s) {
	for (auto& c : s) {
		c = tolower(c);
	}
	return s;
}

void testIntArr(int(&arr)[3]) {
	for (auto& c : arr) {
		cout << c << endl;
	}
	return;
}

void error_msg(initializer_list<string> il) {
	for (auto beg = il.begin(); beg != il.end(); beg++)
		cout << *beg << " ";
	cout << endl;
	return;
}


int main(int argc,char **argv) {
	//*************************test Program6.7
	//string s1;
	//do {
	//	cout << "enter Y show your the value of count,enter N close the program" << endl;
	//	cin >> s1;
	//	if (s1 == "Y")
	//		cout << test_static_value()<<endl;
	//} while (s1 != "N");
	//cout<<"value of fun 2 "<< test_static_value2()<<endl;

	//**************************test Program 6.12
	//string s1;
	//string s2;
	//string* s = &s2;
	//cout << "enter string s1,s2" << endl;
	//cin >> s1 >> s2;
	//change(s1, s);
	//cout << "change the contain of  s1 and s2" << endl;
	//cout << "s1: " << s1 << endl;
	//cout << "s2: " << s2 << endl;

	//*********************test Program6.17 & 6.19
	//string s1;
	cin >> s1;
	//getline(cin, s1);
	//cout << "check whether there is Toper Char: " << ((checkTopChar(s1))? "Yes":"No")<< endl;
	//cout << "Turn the toper to lower format: " << TurnLowChar(s1) << endl;

	//*********************test Program 6.23
	//int intArr[] = { 2,3,3.14 };
	//int intArr2[3] = { 2,3,4 };
	//int intArr3[4] = { 1,2,3,4 };
	//testIntArr(intArr);
	//testIntArr(intArr2);

	//****************test Program 6.25
	//for (decltype(argc) i = 0; i < argc; i++) {
	//	const char* s;
	//	s = *(argv + i);
	//	if (s)
	//	{
	//		while (*s) {
	//			cout << *s++;
	//		}
	//	}
	//	cout << endl;
	//}

	//*************************test program6.27
	string s1;
	while (getline(cin, s1)) {
		if (s1 != "string")
			error_msg({ "it","is",s1,"not","string" });
		else
			error_msg({ "it","is",s1 ,"."});
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值