Sample 4.2:string.cpp

来源:互联网 发布:淘宝快递助手在哪订购 编辑:程序博客网 时间:2024/04/28 21:01
#include<iostream>#include<cstring>int main(){    using namespace std;    const int Size = 15;    char name1[Size];    char name2[Szie] = "C++owboy";    cout << "Howdy! I'm " << name2;    cout << "! What's your name?\n";    cin >> name1;    cout << "Well, " << name1 << ", your name has ";    cout << strlen(name1) << " letters and is stored\n";    cout << "in an array of " << sizeof (name1) << " bytes.\n";    cout << "Your initial is " << name1[0] << ".\n";    name2[3] = '\0';    cout << "Here are the first 3 characters of my name:";    cout << name2 << "\n";    return 0;}

原创粉丝点击