美文网首页
4.5 cin.get()读入字符串存入字符数组

4.5 cin.get()读入字符串存入字符数组

作者: 壹顾倾城 | 来源:发表于2020-01-09 11:48 被阅读0次
    • 程序来源 :C++ primer plus
    • 章 节 :4.5
    • 名 称 :instr3.cpp
    • 功 能 :输出字符串
    • 开发时间 :2020-1-9
    • 版 本 :v1.0
    • 运行测试 :通过
        /********************************
     * 程序来源 :C++ primer plus
     * 章    节 :4.5
     * 名    称 :instr3.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.get(name,ArSize); //get(name,length)
                            //读取一行,以回车结束,保存数据时有空格替换回车 
                            //准备读取下一行 cin.get() 
        cin.get();          //处理回车,准备读取下一行 
        cout << "Enyer you favorite dessert:\n";
        cin.get(dessert, ArSize);   //没有几机会输入 
        cout << "I have some delicious " << dessert;
        cout << " for you," << name;
        
        return 0;
    }
    
    /**********************************
     *            程序输出            * 
     ********************************** 
    Enter you name:
    Micro bike
    Enyer you favorite dessert:
    pie, habange
    I have some delicious pie, habange for you,Micro bike
    --------------------------------
    Process exited after 18.45 seconds with return value 0
    请按任意键继续. . .
    
    **********************************/ 
    

    运行结果:

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

    相关文章

      网友评论

          本文标题:4.5 cin.get()读入字符串存入字符数组

          本文链接:https://www.haomeiwen.com/subject/feryactx.html