知识库

C++语言开发示例:13. 字符串类型4

2025-02-01 20:24:33 李腾 1 次阅读

strtype4.cpp

#include <iostream>
#include <string>
#include <cstring>

int main()
{
    using namespace std;
    char charr[20];
    string str;

    cout << "Length of string in charr before input: "
         << strlen(charr) << endl;
    cout << "Length of string in str before input: "
         << str.size() << endl;
    cout << "Enter a line of text:\n";
    cin.getline(charr, 20);
    cout << "You entered: " << charr << endl;
    cout << "Enter another line of text:\n";
    getline(cin, str);
    cout << "You entered: " << str << endl;
    cout << "Length of string in charr after input: "
         << strlen(charr) << endl;
    cout << "Length of string in str after input: "
         << str.size() << endl;
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:13. 字符串类型4

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!