您的位置:首页 > 编程语言 > C语言/C++

关于C++的字符及字符串

2010-06-29 06:06 197 查看
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    string s1 = "hello";
    const char *s2 = "hello";
    char cs[] = "hello";
    cout << "sizeof(/"hello/"):" << sizeof("hello") << endl;//输出6,包括最后的结束符
    cout << "strlen(/"hello/"):" << strlen("hello") << endl;//输出5,不包括最后的结束符
    cout << "sizeof(s1):" << sizeof(s1) << endl;//输出4,在32PC上,指针的大小是4
    cout << "sizeof(s2):" << sizeof(s2) << endl;//输出4,在32PC上,指针的大小是4
   
    cout << sizeof(cs)/sizeof(char) << endl; //输出6,包括最后的结束符
    cout << s1.length() << endl;    //输出5,不包括最后的结束符
    cout << s1.size() << endl;      //输出5,不包括最后的结束符
    cout << strlen(s1.c_str()) << endl;//输出5,不包括最后的结束符

    system("PAUSE");
    return EXIT_SUCCESS;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ include system string