4.3 读入字符串存入字符数组

2020-01-09  本文已影响0人  壹顾倾城
/********************************
 * 程序来源 :C++ primer plus
 * 章    节 :4.3
 * 名    称 :instr1.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 >> name;     //Micro mike
                     //cin以空格、回车分界,只读取一个单词后结束
                     //其他数据在缓冲区等待下一个cin 
    cout << "Enyer you favorite dessert:\n";
    cin >> dessert;   //cake pie
    cout << "I have some delicious " << dessert;
    cout << " for you," << name;
    
    return 0;
}

/**********************************
 *            程序输出            * 
 ********************************** 
Enter you name:
Micro bike
Enyer you favorite dessert:
I have some delicious bike for you,Micro
--------------------------------
Process exited after 8.412 seconds with return value 0
请按任意键继续. . .

**********************************/ 

运行结果:

Enter you name:
Micro bike
Enyer you favorite dessert:
I have some delicious bike for you,Micro
--------------------------------
Process exited after 8.412 seconds with return value 0
请按任意键继续. . .

上一篇下一篇

猜你喜欢

热点阅读