- 程序来源 :C++ primer plus
- 章 节 :4.2
- 名 称 :string.cpp
- 功 能 :输出字符串
- 开发时间 :2019-10-29
- 版 本 :v1.0
- 运行测试 :通过
/********************************
* 程序来源 :C++ primer plus
* 章 节 :4.2
* 名 称 :string.cpp
* 功 能 :输出字符串
* 开发时间 :2019-10-29
* 版 本 :v1.0
* 运行测试 :通过
*******************************/
#include <iostream>
#include <cstring>
using namespace std;
int main() {
const int Size = 15;
char name1[Size]; //size: 15
char name2[Size] = "C++owboy"; //size: 15, len:8
cout << "Howboy I'm " << name2;
cout << "! what's you name?\n";
cin >> name1; //basicman
cout << "well," << name1 <<",your name has "; //basicman
cout << strlen(name1) <<" letters and is stored\n"; //8
cout <<"in an array of " << sizeof(name1) <<" bytes.\n"; //15
cout <<"You initial is "<< name1[0] <<".\n"; //b
name2[3] = '\0'; // end name2 name2[]="C++\0"
cout << "Here are he first 3 characters of my name ";
cout << name2 << endl; //C++
return 0;
}
运行结果:
Howboy I'm C++owboy! what's you name?
BasicMan
well,BasicMan,your name has 8 letters and is stored
in an array of 15 bytes.
You initial is B.
Here are he first 3 characters of my name C++
--------------------------------
Process exited after 6.358 seconds with return value 0
请按任意键继续. . .
网友评论