关于文件流的那点小事
来源:互联网 发布:共享栈算法 编辑:程序博客网 时间:2024/06/10 06:17
#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){int a;vector<int > num_count;while(cin>>a){num_count.push_back(a);} int word_count;cin>>word_count;cout<<"please input the number that you want to find"<<endl;cout<<count(num_count.begin(),num_count.end(),word_count);system("pause");return 0;}
今天编写了这个程序,运行时 发现 cin>>word_count这一行死活不出现 直接跳过,让我产生了很大的迷惑,在c++群里问了别人之后发现时 结束 ctrl+z的那里出错了,当我在输入一串数字之后,用ctrl+z结束while时 产生的文件流仍在缓冲区,导致直接cin>>word_count跳过。经过我查了百度之后。对程序进行了更改。
#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){int a;vector<int > num_count;while(cin>>a,!cin.eof()){num_count.push_back(a);}cin.clear(); int word_count;cin>>word_count;cout<<"please input the number that you want to find"<<endl;cout<<count(num_count.begin(),num_count.end(),word_count);system("pause");return 0;}经过这样的改动 程序完美运行 哈哈
- 关于文件流的那点小事
- RecyclerView关于notifyItemRemoved的那点小事
- RecyclerView关于notifyItemRemoved的那点小事!
- RecyclerView关于notifyItemRemoved的那点小事
- 关于计算机中数值的表示的那点小事
- struts2的那点小事
- Servlet的那点小事
- 那些年,关于大型机的那点小事。
- 关于"堆栈"和"堆"的那点小事
- 关于C++ 构造函数的那点小事
- 关于Animation的那点小事,天气特效篇
- C语言格式化的那点小事
- java byte 类型的 那点小事
- Ubuntu的那点小事(一)
- 游标那点小事
- jdbc那点小事
- 初始化那点小事
- qsort那点小事
- job
- JavaScript性能优化总结
- Android Handler机制详解:在线程中新建Handler
- ubuntu
- 如果反复逃来逃去,那最终就是在逃避生活
- 关于文件流的那点小事
- Android自动化测试解决方案
- 程序猿段子(转自果壳网)
- ie6下png透明
- Android Canvas绘图详解(图文)
- windows核心编程-作业
- SGU128 Snake
- Android屏幕计量单位详解
- [Android面试题-3] Activity的四种加载模式