1.9 字符数组操作

2017年1月8日 0 条评论 1.48k 次阅读 0 人点赞
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void main(){
	cout << "char a[] = 123456789!,b[11]" << endl;
	char a[] = "123456789!", b[11];
	cout << "the numbers of a[] is:" << sizeof(a) <<endl;
	cout << "reverse a[],print will be  !987654321" << endl;
	reverse(a, a+11-1);
	copy(a, a+sizeof(a), ostream_iterator<char>(cout));

	cout << endl << "another way of print a[] :cout << a << endl;" << endl;
	cout << a << endl;

	cout << "copy a[] to b[]" << endl;
	copy(a, a+sizeof(b), b);
	cout << b << endl;
	
	cout << "sort a[]" << endl;
	sort(a, a+sizeof(a)-1);
	cout << a << endl;

	cout << "reverse copy a[] to b[]" << endl;
	reverse_copy(a, a+sizeof(a)-1, b);
	cout << b << endl;
	
	cout << "reverse part (b+2, b+8) of b[]" << endl;
	reverse(b+2, b+8);
	cout << "print all of b[]" <<endl;
	cout << b <<endl;
	cout << "print (b+2, b+8) of b[] " <<endl;
	copy(b+2, b+8, ostream_iterator<char>(cout));
	cout <<endl;
	cout << "print (b+3, b+5) of b[] ,the numbers of print will be 5-3=2" <<endl;
	copy(b+3, b+5, ostream_iterator<char>(cout));
	cout << endl;

	cout << "greater sort of a[]" <<endl;
	sort(a, a+sizeof(a)-1, greater<char>());
	cout << a <<endl;

	char c[] = "wrrheeeea!";
	cout << "find 'e' and 'O' in c[] = wrrheeeea! ,if find it ,print will be '1' nor '0'" << endl;
	cout << (*find(c, c+10, 'e') == 'e') << " "
		<< (*find(c, c+10, 'O') == 'O') <<endl;
}

Sevenfal

这个人太懒什么东西都没留下

文章评论(0)