首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

有个小程序有点不懂 阿

2012-03-09 
有个小程序有点不懂 请指教阿//locale_isalpha.cpp//compilewith:/EHsc#includelocale#includeiostream

有个小程序有点不懂 请指教阿
//   locale_isalpha.cpp
//   compile   with:   /EHsc
#include   <locale>
#include   <iostream>

using   namespace   std;

int   main(   )      
{
      locale   loc   (   "German_Germany "   );
      bool   result1   =   isalpha   (   'L ',   loc);/////这里loc是拿来干什么的阿???
      bool   result2   =   isalpha   (   '@ ',   loc);
      bool   result3   =   isalpha   (   '3 ',   loc);

      if   (   result1   )
            cout   < <   "The   character   'L '   in   the   locale   is   "/////可不可以告诉我这句话什么意思啊
                      < <   "alphabetic. "   < <   endl;
      else
            cout   < <   "The   character   'L '   in   the   locale   is   "
                      < <   "   not   alphabetic. "   < <   endl;

      if   (   result2   )
            cout   < <   "The   character   '@ '   in   the   locale   is   "
                      < <   "alphabetic. "   < <   endl;
      else
            cout   < <   "The   character   '@ '   in   the   locale   is   "
                      < <   "   not   alphabetic. "   < <   endl;

      if   (   result3   )
            cout   < <   "The   character   '3 '   in   the   locale   is   "
                      < <   "alphabetic. "   < <   endl;
      else
            cout   < <   "The   character   '3 '   in   the   locale   is   "
                      < <   "   not   alphabetic. "   < <   endl;
}


[解决办法]
是不是检测是不是这个语言的字符
[解决办法]
bool result1 = isalpha ( 'L ', loc);/////这里loc是拿来干什么的阿???

loc是代表一个位置,isalpha( 'L ',loc)是判断在loc位置上的这个字符是不是L,如果是,就返回true给result1,如果不是L,就返回false给result1

所以对于一个字符串来说,可以这样用:

char *p= "hello ";
bool result1 = isalpha ( 'e ', 1);

判断位置1是否是e字母
[解决办法]
这是本地化设置,
意思是
locale loc ( "German_Germany " ); //设置本地为德国(语)



bool result1 = isalpha ( 'L ', loc);/////
//判定 'L '在德语文字中是否是个字母,//是否字母数字,各国判定标准不同的

热点排行