注册 登录
编程论坛 C++教室

string :: size_type 的疑问

死了都要C 发布于 2007-12-15 15:00, 1196 次点击
以下是显示```我们输入的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没有定义``第一次使用``
这是怎么回事啊```应该怎么解决啊```请帮帮忙谢谢``
1 回复
#2
中学者2007-12-16 12:25
我也没用过,但是我想应该是你用的string类是放在std里面的,
所以要写成 using std::string::size_type
1