首页 新闻 会员 周边

isspace函数, const字符串和非const字符串的最后一个字符(‘\0’)的区别

0
悬赏园豆:10 [已解决问题] 解决于 2015-07-23 10:57

#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main( void )
{    
    //正确
    const string str2 = "ab";
    cout << isspace(str2[2]) << endl;

//    报错
//    string str1 = "ab";
//    cout << isspace(str1[2]) << endl;

    return 0;
}

在vs2010中,是编译器的问题么?

Covit的主页 Covit | 初学一级 | 园豆:195
提问于:2015-07-22 13:54
< >
分享
最佳答案
0

应该不会,之所以出错,估计是isspace实现的版本问题,对0的处理问题

string str1 = "ab";
char* ch = &(str1[2]);
cout << isspace(*ch) << endl;

Debug时看看ch的地址和str1指向的地址内容,比较一下

收获园豆:10
2012 | 高人七级 |园豆:21230 | 2015-07-23 09:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册