#include "stdafx.h"
#include"iostream"
#include"math.h"
#include"stdio.h"
#include"cstdlib"
#include"string"
#include"cstring"
using namespace std;
#define Max 20
struct player
{
string name;
char sex;
int high;
}; int main(void)
{
struct player bit[3];
int i;
cout << "press enter to start:";
for (i = 0; i<3; i++)
{
cin.get(); cout << "************player " << i << "***************" << endl;
cout << "now input player " << i << "'s name:"; getline(cin, bit[i].name);
cout << "now input player " << i << "'s sex:";
cin >> bit[i].sex;
cout << "now input player " << i << "'s high:";
cin >> bit[i].high; }
cout << "##################################################" << endl;
for (i = 0; i<3; i++)
{
cout << "player " << i << "'s name is" << bit[i].name << "and his sex is" << bit[i].sex << "and the high is" << bit[i].high << endl;
}
}

  上述代码第一个循环里,i=0执行正常,i=1的时候就会跳过输入名字这一项,直接到性别那里,如果i初值为1,则2的时候也跳过。

百度得知是cin和getline区别的问题。

在你写getline()函数之前,一定有使用过了回车了吧
不论你输入的是字符,数字或是回车,空格符,getline()函数都接收
而cin>>这种输入方式却是忽略回车的,如果你在getline()之前cin的一个数,回车被cin忽略了,却被getline函数接收了,感觉就是这条语句被跳过了
所以解决的办法是在getline函数之前再使用getline一次,将输入流里的回车符接收掉,后面就能正常输入了 百度知道的答案http://zhidao.baidu.com/link?url=-67TNObP8QxnE7tROIXviIDcS1SPWA7t5GzBcLV5yxu8sRfVS8W_H-0VR-HPW-ACbPAalWdFTfBGk3B5fnYqrq

C++中getline被跳过的更多相关文章

  1. .htaccess中301强制跳转到带www前缀或不带www的域名

    相信很多站长朋友都有这样的的问题出现.即带www前缀的域名与不带www前缀的顶级域名收录情况是不同的.这个问题主要是由于搜索引擎对于顶级域名与二级域名权重判定不同造成的.毫无疑问地,唯一的域名能够给你 ...

  2. iframe中的各种跳转方法

    iframe中的各种跳转方法(转)   一.背景A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,在D中跳转页面的写法区别如下. 二.JS跳转window.l ...

  3. php开发中的页面跳转方法总结

    PHP页面跳转实现的功能就是将网站中一个网页跳转到另一个网页中.对于刚刚学习PHP语言的朋友来说,是必须要掌握的基础方法. 页面跳转可能是由于用户单击链接.按钮等触发的,也可能是系统自动产生的.页面自 ...

  4. 可以放在html代码中的自动跳转代码

    可以放在html代码中的自动跳转代码 有3种方法可以实现html的页面跳转,1,refresh   2,onload事件中加入代码  3,js实现 1.<html><body> ...

  5. Python+selenium自动化测试中Windows窗口跳转方法

    Python+selenium自动化测试中Windows窗口跳转方法 #第一种方法 #获得当前窗口 nowhandle=driver.current_window_handle #打开弹窗 drive ...

  6. MVC中常用的跳转方法

    MVC中常用的跳转方法 这里总结了几种MVC中的跳转方式,主要汇总了前端页面跳转,后台的跳转,和过滤器中的跳转方式. 1.在前端页面的跳转方式 <!--属性形式---> <a hre ...

  7. JS funtion()中URL不跳转后台action问题

    JS funtion()中URL不跳转后台action问题 今天遇到一个百思不得其解的问题,到现在解决了,但是仍然不知道所以然(估计是因为域名不一致导致的),记录一下 $.get(actionUrl, ...

  8. Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接

    在文章 Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接(一) 中我们成功的为/feedback/feedback_stats/路径自定义了使用tem ...

  9. angular2 Router类中的路由跳转navigate

    navigate是Router类的一个方法,主要用来路由跳转. 函数定义 navigate(commands: any[], extras?: NavigationExtras) : Promise` ...

随机推荐

  1. 由源码密码文件转转化成keystore

      1.android 源码目录build\target\product\security 取platform.pk8 platform.x509.pem放到一个目录下 E:\sign\convert ...

  2. C++ List的用法(整理)

    转自http://blog.csdn.net/lskyne/article/details/10418823 Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和 ...

  3. LUA GC 简单测试

    function table.count(t) if type(t) ~= "table" then assert(false) return end for k, _ in pa ...

  4. pandas 时间序列resample

    resample与groupby的区别:resample:在给定的时间单位内重取样groupby:对给定的数据条目进行统计 函数原型:DataFrame.resample(rule, how=None ...

  5. python 转 exe -- py2exe库实录

    本文基于windows 7 + python 3.4 把python程序打包成exe,比较好用的库是py2exe 其操作步骤是: --> 编写python程序 --> 再额外编写一个导入了 ...

  6. 《WCF服务编程第三版》知识点摘录

  7. Objective-c文件读取

  8. Android nDrawer

    GitHub上一款流行的侧滑,附上自己as编译过的源码http://download.csdn.net/detail/lj419855402/8559039. 留个纪念,说不定以后用得到. 依赖一个l ...

  9. [CareerCup] 4.9 All Paths Sum 所有路径和

    4.9 You are given a binary tree in which each node contains a value. Design an algorithm to print al ...

  10. [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵

    11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a m ...