输入的C型字符串有问题 [英] Problem with input C-type string

查看:88
本文介绍了输入的C型字符串有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char s1[1024], s2[1024];
cin.get(s1, 1024);
cin.get();
cin.get(s2, 1024);



当我通过按Enter键输入s1为空字符串时,程序立即结束,并且我没有机会输入s2.为什么???我认为cin.get()已经吃了Enter字符"\ n".



When I input s1 an empty string by press Enter, the program ends immediately and I have no chance to input s2. Why??? I think cin.get() has already eaten the Enter character ''\n''.

推荐答案

您需要清除第一个cin.get()的错误状态呼叫,因为它没有收到任何有效的输入.检查< istream> [
You need to clear the error state from the first cin.get() call, as it has not received any valid input. Check the <istream>[^] reference on MSDN.


这篇关于输入的C型字符串有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆