程序来源 :C++ primer plus
章 节 :4.4
名 称 :instr2.cpp
功 能 :输出字符串
开发时间 :2020-1-9
版 本 :v1.0
运行测试 :通过
/********************************
* 程序来源 :C++ primer plus
* 章 节 :4.4
* 名 称 :instr2.cpp
* 功 能 :输出字符串
* 开发时间 :2020-1-9
* 版 本 :v1.0
* 运行测试 :通过
*******************************/
#include <iostream>
#include <cstring>
using namespace std;
int main() {
const int ArSize = 20;
char name[ArSize];
char dessert[ArSize];
cout << "Enter you name: \n";
cin.getline(name,ArSize); //getline(name,length)
//读取一行,以回车结束,保存数据时有空格替换回车
//准备读取下一行 cin.getline()
cout << "Enyer you favorite dessert:\n";
cin.getline(dessert, ArSize);
cout << "I have some delicious " << dessert;
cout << " for you," << name;
return 0;
}
/**********************************
* 程序输出 *
**********************************
Enter you name:
micro bike
Enyer you favorite dessert:
coke,banana
I have some delicious coke,banana for you,micro bike
--------------------------------
Process exited after 12.8 seconds with return value 0
请按任意键继续. . .
**********************************/
运行结果:
Enter you name:
micro bike
Enyer you favorite dessert:
coke,banana
I have some delicious coke,banana for you,micro bike
--------------------------------
Process exited after 12.8 seconds with return value 0
请按任意键继续. . .
网友评论