cin.getline在输入char时:

using namespace std;
const int ArSize = ;
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时的不同的更多相关文章

  1. c++中字符输入函数getline、cin.getline区分

    1.cin>>s; s能够是:string  s.char s[]; 这个是ostream中的函数.遇到' '(空格) , '\n'(换行),就会自己主动结束,因此假设用cin读取字符串, ...

  2. [C/C++] 输入函数getline(cin,str) 与cin.getline(str,int)区别

    cin.getline()函数是处理数组字符串的,其原型为cin.getline(char * , int),第一个参数为一个char指针,第二个参数为数组字符串长度. getline(cin,str ...

  3. c++ --> cin和cout输入输出格式

    cin和cout输入输出格式 Cout 输出 1>. bool型输出 cout << true <<" or " << false < ...

  4. cin.get()和cin.getline()之间的区别

    cin.getline()和cin.get()都是对输入的面向行的读取,即一次读取整行而不是单个数字或字符,但是二者有一定的区别. cin.get()每次读取一整行并把由Enter键生成的换行符留在输 ...

  5. c++之cin/cin.get/cin.getline()详解

    C++输入过程中,是把输入加载到缓冲区中,然后对缓冲区中的字符进行读取.cin,cin,get(),cin.getline()三个函数虽然都能进行数据读取,但是它们对缓冲区内数据的处理方法是不同的(如 ...

  6. 日常笔记4关于cin、cin.get()、cin.getline()、getline()使用区别

    1.关于PAT中段错误 使用字符数组出现错误: char str[256]; 报错段错误,然后改用C++中的string 改成: string str; 同char数组一样,也可以使用下标来取单个字符 ...

  7. Java中char和String的相互转换

    转自:http://blog.csdn.net/yaokai_assultmaster/article/details/52082763 Java中char是一个基本类型,而String是一个引用类型 ...

  8. C++中几个输入函数的用法和区别(cin、cin.get()、cin.getline()、getline()、gets()、getchar())

    1.cin>> 用法1:最基本,也是最常用的用法,输入一个数字: #include <iostream>using namespace std;main (){int a,b; ...

  9. C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法----细节决定成败 (sort用法)

    C++中cin.cin.get().cin.getline().getline().gets()等函数的用法 学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有 ...

随机推荐

  1. Delphi BitBtn组件

  2. 如何使用sqlalchemy获取表的主键、以及每一个字段名和对应类型

    使用sqlalchemy获取到的结果只包含数据,不包含字段,那么我们如何获取到对应字段和其属性呢?以及如何获取某张表的主键呢? # -*- coding:utf-8 -*- # @Author: Wa ...

  3. python动态添加属性

    class A: def __init__(self, info ={}): self.info = info def __getattr__(self, item): return self.inf ...

  4. c++字符串的输入

    先声明一下字符串的初始化:当初始赋值的时候一定是反斜杠0(\0)有三种方式“”,{‘\0’}."\0"(如果是已经赋值的我们可以采用memset(recvbuf, '\0', si ...

  5. ceph问题汇总

    1. [ceph_deploy][ERROR ]RuntimeError: Failed to execute command: yum -y install epel-release 解决方案 进入 ...

  6. Vue自行封装常用组件-倒计时

    倒计时组件,比较复杂一点,大神勿调侃,精确到毫秒,因为项目中多次出现倒计时,所以拿出来分享下 使用方法:1.在父组件中引入"uni-countdown" //import uniC ...

  7. python中import cv2遇到的错误及安装方法

    参考链接:https://blog.csdn.net/yuanlulu/article/details/79017116 从x86_64 + ubuntu18.04 + python3.5中impor ...

  8. spring ObjectFactory

    AspectJAwareAdvisorAutoProxyCreator implements PostProcessor postProcessorAfterInitialization(Object ...

  9. Linux tcpdump命令详解与Wireshark

    简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...

  10. idea 使用Tomcat 部署war 和 war exploded的区别

    war模式:将WEB工程一包的形式上传到服务器中. war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器. 解析: war 模式这种可以称为是发布模式(完整的项目),将项目打成 ...