c++的文件结束符不是ctrl+z或者ctrl+d吗???c++高手来啊
#include<iostream>#include<vector>usingnamespacestd;intmain(){vector<int>ivec;intival...
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> ivec;
int ival;
cout<<"Enter numbers(Ctrl+Z to end)"<<endl;
while(cin>>ival)
ivec.push_back(ival);
if(ivec.size()==0)
{
cout<<"no elements?"<<endl;
return -1;
}
cout<<"Sum of each pair of adjacent elements in the vector:"<<endl;
for(vector<int>::size_type index;index!=ivec.size()-1;index+=2)
{
cout<<ivec[index]+ivec[index+1]<<"/t";
if(index+1%6==0)
{
cout<<endl;
}
if(ivec.size()%2!=0)
{
cout<<endl<<"the last number is not been summed "
<<"and it's value is "
<<ivec[ivec.size()-1]<<endl;
}
return 0;
}
} 展开
#include<vector>
using namespace std;
int main()
{
vector<int> ivec;
int ival;
cout<<"Enter numbers(Ctrl+Z to end)"<<endl;
while(cin>>ival)
ivec.push_back(ival);
if(ivec.size()==0)
{
cout<<"no elements?"<<endl;
return -1;
}
cout<<"Sum of each pair of adjacent elements in the vector:"<<endl;
for(vector<int>::size_type index;index!=ivec.size()-1;index+=2)
{
cout<<ivec[index]+ivec[index+1]<<"/t";
if(index+1%6==0)
{
cout<<endl;
}
if(ivec.size()%2!=0)
{
cout<<endl<<"the last number is not been summed "
<<"and it's value is "
<<ivec[ivec.size()-1]<<endl;
}
return 0;
}
} 展开
展开全部
#include<iostream>
using namespace std;
int main()
{
int i = 0;
while(true){
cin>>i;
if(cin.eof()){
cout<<"eofbit."<<endl;
break;
}
if(cin.bad())
cout<<"badbit."<<endl;
if(cin.fail())
cout<<"failbit/badbit."<<endl;
cin.clear();
}
return 0;
}
//可以按几个建试试,如果输出eofbit并停止程序的话,那个键就是文件结束符。
//还有文件结束符是系统定义的,不是C++定义的。
//= =汝看C++ Primer?
//那上面写了吧。。Win里按住Ctrl+z还要按Enter/Return键。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询