码迷,mamicode.com
首页 > 编程语言 > 详细

c++中字符输入函数cin.getline在输入char与string时的不同

时间:2019-01-16 16:44:22      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:const   using   color   new   enter   class   div   stream   nbsp   

cin.getline在输入char时:

using namespace std;
    const int ArSize = 20;
    char name[ArSize];
    char dessert[ArSize];


    cout << "Enter your name:\n";
    cin.getline(name, ArSize);  // reads through newline
    cout << "Enter your favorite dessert:\n";
    cin.getline(dessert, ArSize);

getline在输入string时:

#include<iostream>
#include<string>
using namespace std;

 

int main()
{
    string name;
    string dessert;


    cout<<"Enter your name:\n";
    getline(cin,name);
    cout<<"Enter your favorite dessert:\n";
    getline(cin,dessert);

 

c++中字符输入函数cin.getline在输入char与string时的不同

标签:const   using   color   new   enter   class   div   stream   nbsp   

原文地址:https://www.cnblogs.com/joelwang/p/10277302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!