用C++语言编写程序

来源:百度知道 编辑:UC知道 时间:2024/06/11 17:12:29
用C++语言编写程序,要求输入一行英文文字,把每个单词的首个字母改为大写字母....哪个高手知道怎么编写啊????

#include<iostream>
using namespace std;
int main()
{
char m ;
cout<<"依次输入请不要超过256个字符"<<endl;
{
char *p = new char[256] ; // 当然 也可以 char p[256] 把最后一句
cin.getline(p,256); // delete p 去掉就可以
bool ok =true;
for(int i = 0 ; p[i] != '\0';i ++)
{
if(p[i] != ' ')
{
if(ok)
p[i] -= 32;
ok =false;
}
else
ok = true;
}

for(int a = 0; a <= i ; a++)
cout<<p[a];
cout<<endl;
delete p;
}
return 0;

用动态数组来存储 将第一个字符和以后每个空格之后的字母值减32 直到结束

#include <string>
#include <iostream>
using namespace std;

typedef string::iterator SIT;
void upper(SIT c)
{
if( *c < 123 && *c > 96)
*c = *c - 32;//将小写字母变成大写
}
int main()
{
string s;