关于输入getline
此函数可读取整行,包括前导和嵌入的空格,并将其存储在字符串对象中。
getline 函数如下所示:
getline(cin, inputLine);
其中 cin 是正在读取的输入流,而 inputLine 是接收输入字符串的 string 变量的名称。下面的程序演示了 getline 函数的应用:
// This program illustrates using the getline function
//to read character data into a string object.
#include <iostream>
#include <string> // Header file needed to use string objects
using namespace std;
int main()
{
string name;
string city;
cout << "Please enter your name: ";
getline(cin, name);
cout << "Enter the city you live in: ";
getline(cin, city);
cout << "Hello, " << name << endl;
cout << "You live in " << city << endl;
return ;
}
关于输入getline的更多相关文章
- c++面向行的输入getline()和get()
来源:c++ primer plus 在c++里当我们输入一个字符串时习惯用cin,但是cin只能读取一段不含空格的字符串,如果我们需要读取一段包含空格的字符串时,就需要用到getline()或get ...
- C++中的字符串输入getline
http://www.cnblogs.com/wanghao111/archive/2009/09/05/1560822.html 1 #include <iostream> 2 #inc ...
- C plus plus primer plus
1,运算符,操作数; 使用相同的符号(基本运算符,+ - * / %),进行多种操作(指使用一个运算符符号,对不用类型的变量进行操作,int ,float,double),此概念将运算符的重载(op ...
- C++ Primer Plus 文章17章 进,输出和文件
文章17章 进.输出和文件 1.当到达输入句子.他将刷新输出缓冲区满输出电流 2.streambuf分类 它提供了用于各种操作的一个缓冲 ios_base类表示流的一般特征 ios基础的类ios_ba ...
- 题解-洛谷P1184 高手之在一起
https://www.luogu.org/problemnew/show/P1184 (题目出处) 见到地名,自然就想到字符串了.可以从第一天开始,将她的位置与高手方便取得地方一一比较,(char字 ...
- C++标准模板库(STL)介绍:string的基本用法
1.带空格的字符串的输入 getline(cin, str)
- DS博客作业03—栈和队列
1.本周学习总结 本周学习了栈和队列两种数据结构,分别对应后进先出,先进先出两种数据操作 学会栈的特殊类型-共享栈,队列的特殊类型-循环队列的一系列操作 学会熟练使用栈和队列的STL容器,使代码简洁 ...
- C++ Review
#include "iostream" #include "iomanip" #include "cstdio" using namespa ...
- c++ primer plus 第6版 部分一 1-4章
c++ primer plus 第6版 源代码 ---编译器---目标代码---连接程序(启动代码--库代码)---可执行代码 源代码扩展名:c cc cxx C cpp ...
随机推荐
- 多年iOS开发经验总结(一)
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; ...
- 英语发音规则---B字母
英语发音规则---B字母 一.总结 一句话总结: 1.B发[b]音? bike [baɪk] n. 自行车 bus [bʌs] n. 公共汽车 bag [bæg] n. 袋:猎获物 baby ['be ...
- idea设置Template
在eclipse里面经常会用到syso和main类似这样的内容,但是idea工具里面没有,可以通过 Editor ==> Live templates ==> 1.首先创建一个自己的Te ...
- 25.QT进度条
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> 5 #include <QProgressBar&g ...
- SQLserver中用convert函数转换日期格式(2)
), ): :57AM ), ): ), ): ), ): ), ): ), ): ), ): ), ): , ), ): :: ), ): :::827AM ), ): ), ): ), ): ), ...
- Excel—— [导入到数据库] or 将数据 [导入到Excel]
将Excel导入到数据库实现如下: 前台代码: @model IEnumerable<Model.Student> @{ Layout = null; } <!DOCTYPE htm ...
- wampserver的安装及使用配置方法
在安装wampserver的过程中,根据本人在安装过程中遇到的问题,在此做个总结,与小伙伴们分享一下下~~~. 1. 何处获得Wamp ★ 在自己的Windows电脑上Web服务器软件 - Wamp. ...
- genemotion
genemotion 问题 https://blog.csdn.net/beiminglei/article/details/17399333 https://www.jianshu.com/p/f8 ...
- 0-NULL-nullptr
NULL In C A null-pointer constant is an integral constant expression that evaluates to zero (like 0 ...
- luogu P5290 [十二省联考2019]春节十二响 优先队列_启发式合并
思维难度不大,在考上上写的启发式合并写错了,只拿了 60 pts,好难过QAQ 没什么太难的,在考场上想出链的部分分之后很容易就能想到正解.没错,就是非常短的启发式合并.注意一下,写的要漂亮一点,否则 ...