将strng类型变量字母转换成大写字母

/*  
* Copyright (c) 2012, 烟台大学计算机学院  
* All rights reserved.  
* 作    者:解晓东   
* 完成日期:2012 年 11 月 17 日  
* 版 本 号:v1.0  
*  
* 输入描述:                     
* 问题描述:                         
* 程序输出:                         
* 问题分析: 
* 算法设计:  
*/  

# include <iostream>
# include <cctype>//toupper()函数的声明
# include <string>//string的声明

using namespace std;

int main()
{
	string str1;//定义string类型变量str1

	cout << "please input strings:";//提示
	cin  >> str1;//输入str1

	//string.size()函数功能返回str1的字符个数
	for (string::size_type count = 0; count != str1.size(); ++count)//string::size_type是数据类型
	{
		str1[count] = toupper(str1[count]);//toupper()函数是把str1中字母都转换成大写,tolower()转换成小写
	}

	cout << str1//输出str1转换后的
		 << endl;//输出换行

	return 0;
}

将strng类型变量字母转换成大写字母_第1张图片

你可能感兴趣的:(将strng类型变量字母转换成大写字母)