| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5367 人关注过本帖
标题:把输入string 里的小写字母变成大写字母问题(部分解决)
只看楼主 加入收藏
沿途有鬼
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-7-20
收藏
得分:0 
谢谢各位的回答,虽然还是不是很明白~
2008-08-05 10:27
zerocn
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-4-11
收藏
得分:0 
islower函数用不对,toupper函数也用不对,请参考MSDN

一下的程序能实现你的功能
#include<iostream>
#include <string>
#include <stdlib.h>

using namespace std;

void Toupper(string &);

int main()
{
    string st("abc");
    cout<<"Enter astring (q to quit): ";
   
   
    while(getline(cin,st))
    {   if(st=="q")
        break;
        cout<<"Enter astring (q to quit): ";
        Toupper(st);
        cout<<st;
    }
    system("pause");
    return 0;
}

void Toupper(string &str)
{  
    for(int i=0;i<str.size();i++)
    if(str[i]>='a' && str[i]<='z')
    str[i]-=32;
}
2008-08-06 21:56
Vegertar
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-8-3
收藏
得分:0 
大写小写全转了
# include <iostream>
# include <string>
# include <cctype>

void to_lower(std::string& s) //转小写
{
    for(int i = 0; i < s.size(); ++i)
         s[i] = tolower( s[i] );
}

void to_upper(std::string& s)  //转大写
{
    for(int i = 0; i < s.size(); ++i)
         s[i] = toupper( s[i] );
}

int main()
{
    std::string s;
    std::cout << "input a string : ";
    std::cin >> s;

    to_lower(s);
    std::cout << s << std::endl;
    to_upper(s);
    std::cout << s << std::endl;

    return 0;
}
2008-08-07 17:27
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
你的  q 跳出循环写在哪里????? 楼主 我没看到啊???
2008-08-10 15:17
elegant87
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-1-15
收藏
得分:0 
我给你写了一个,你看看吧!
这里用到的函数toupper(c);它的功能是如果c是小写的字母,则将小写转换为大写。否则直接返回c。
记住用这个函数需要#include<cctype>头文件的!

//把输入string 里的小写字母变成大写字母

#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int main()
{
    string st;
    cout<<"Enter a string (ctrl+z to quit): ";
    while(getline(cin,st))
    {
       string::size_type ix;
       for(ix=0;ix!=st.size();++ix)
              st[ix]=toupper(st[ix]);
       cout<<"\nChange big word result is: ";
       cout<<st<<endl;
       cout<<"\nEnter a string (ctrl+z to quit): ";
    }
    system("pause");
    return 0;
}
2008-08-11 21:36
xlh5225
Rank: 2
等 级:论坛游民
威 望:2
帖 子:188
专家分:25
注 册:2007-8-14
收藏
得分:0 
有我么困难么?还部分解决,夸张的很
2008-08-11 21:38
快速回复:把输入string 里的小写字母变成大写字母问题(部分解决)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved