问题描述
有时候会遇到这样的问题:
想要从屏幕输入值(cin>>num,num是int类型变量),来对输入值进行处理。但在实际运行中,输入操作却被忽略了,无法进行输入操作。但整个程序又没有语法类问题。
如下边下边例子,是对一串数字进行二分查找某个特定值:
程序过程:
1、从屏幕输入一串有序数字,放入一个vector对象中
2、从屏幕输入一个特定值,在vector对象中进行二分查找此特定值,如果存在,输出此特定值,如果不存在,输出“the number is not existed”
# include<iostream>
# include<fstream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<int> ivec;
int num;
//输入数字
cout << "Please enter the number in sequence" << endl;
while (cin >> num)
ivec.push_back(num);
cout << "Please enter the number that you will look:" << endl;
int number;
cin >> number;
auto beg = ivec.begin();
auto mid = ivec.begin() + ivec.siz

3175

被折叠的 条评论
为什么被折叠?



