| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付赛孚耐:软件保护加密专家
身份认证令牌USB KEY   
共有 584 人关注过本帖
标题:string :: size_type 的疑问
收藏  订阅  推荐  打印 
死了都要C
Rank: 12Rank: 12Rank: 12
来自:四川成都
等级:贵宾
威望:13
帖子:1507
积分:15568
注册:2006-12-7
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: 12Rank: 12Rank: 12
等级:版主
威望:14
帖子:3389
积分:34733
注册:2007-9-14

我也没用过,但是我想应该是你用的string类是放在std里面的,
所以要写成 using std::string::size_type

汇编.....
2007-12-16 12:25
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.061537 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved