关闭

Sample 4.10:strtype4.cpp

316人阅读 评论(0) 收藏 举报
分类:
#include<iostream>
#include<string>
#inclue<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";
    cin.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;

    return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36425次
    • 积分:978
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:63篇
    • 译文:0篇
    • 评论:1条
    文章存档
    最新评论