首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++程序运行的时候终止条件无效,不能运行上面的代码了

2012-10-19 
C++程序运行的时候终止条件无效,不能运行下面的代码了#includeiostream#includevectorusing namespace

C++程序运行的时候终止条件无效,不能运行下面的代码了
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  vector<int> ivec1,ivec2;
  int ival;
  cout<<"Enter elements for the first vector:(32627 to end)"//这行成功显示
  <<endl;
  cin>>ival;
while(ival!=32767)
{
ivec1.push_back(ival);
cin>>ival;
}
//这里我输入1 2 32767 没反应。然后我接着输入control+z还是没反应
  cout<<"Enter elements for the second vector:(32627 to end)"
  <<endl;
  cin>>ival;
  while(ival!=32627)
  {
  ivec2.push_back(ival);
  cin>>ival;
  }
  vector<int>::size_type size1,size2;
  size1=ivec1.size();
  size2=ivec2.size();
  bool result=true;
  for(vector<int>::size_type ix=0;ix!=(size1>size2?size2:size1);++ix)
  {
  if(ivec1[ix]!=ivec2[ix]){
  result=false;
  break;
  }
  }
  if(result)
  if(size1<size2)
  cout<<"The first vector is prefix of the second one."<<endl;
  else if(size1==size2)
  cout<<"Two vectors are equal."<<endl;  
  else
  cout<<"The second vector is prefix of the first one."<<endl;  
  else
  cout<<"No vector is prefix of the other one.";
  return 0;
}
 

[解决办法]

探讨

引用:

到底是32767还是32627,看看清楚你有没有输错


没输错啊。

热点排行