| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1190 人关注过本帖
标题:string :: size_type 的疑问
只看楼主 加入收藏
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
结帖率:66.67%
收藏
 问题点数:0 回复次数:1 
string :: size_type 的疑问
以下是显示```我们输入的2个字符串中谁比谁长```:

#include <iostream>
#include <string>

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

int main(void)
{
    cout << "Please enter tow strings :" << endl ;
   
    string str1, str2 ;
    if( !(cin >> str1 >> str2) )
    {
        return -1 ;
    }
   
    size_type size1, size2 ;
    size1 = str1.size() ;
    size2 = str2.size() ;
   
    string first, second ;
    if ( size1 == size2 )
       cout << "Tow strings have same length." << endl ;
    else if( size1 > size2 )
    {
           first = "First" ;
           second = "second" ;
    }

    else
    {
           first = "Second" ;
           second = "first" ;
    }
   
   
   cout << first  << " string is longer than "
        << second << "string ."
        << endl ;
            
    return 0 ;
}


我发生的问题是```将string :: size_type单独放到程序声明对象时程序没错``
可以我用using声明就回出错```说是size_type没有定义``第一次使用``
这是怎么回事啊```应该怎么解决啊```请帮帮忙谢谢``
搜索更多相关主题的帖子: string type 疑问 size 
2007-12-15 15:00
中学者
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:3554
专家分:80
注 册:2007-9-14
收藏
得分:0 
我也没用过,但是我想应该是你用的string类是放在std里面的,
所以要写成 using std::string::size_type

樱花大战,  有爱.
2007-12-16 12:25
快速回复:string :: size_type 的疑问
数据加载中...
 
   



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

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