# 关于I/O的问题

jianfengshxy 2008-03-13 01:31:45

(in linux)

#include<iostream>
#include<list>
#include<vector>
using namespace std;

int main()
{
vector<int> ivec;
list<int> ilst;
int ival;

cout<<"the vetor's numbers"<<endl;
while(cin>>ival)
ivec.push_back(ival);

cout<<"the list's numbers"<<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();

vector<int>::const_iterator vecit=ivec.begin();
list <int>::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout<<"they are not same"<<endl;
return 0;
}
else
{ for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{ cout<<"they are not same"<<endl;
return 0;
}
}
cout<<"they are same!"<<endl;
}
return 0;
}
...全文
160 12 打赏 收藏 举报

12 条回复

i_coding 2008-03-14
• 打赏
• 举报

i_coding 2008-03-13
• 打赏
• 举报

``````#include <iostream>
#include <list>
#include <vector>
#include <limits> //<----添加此头文件
using namespace std;

int main(void)
{
vector <int>  ivec;
list <int>  ilst;
int ival;
cout << "the vetor's numbers" << endl;
while(cin >> ival)
ivec.push_back(ival);
cin.clear(); //<-----这里
cin.ignore(std::numeric_limits<streamsize>::max(),'\n'); // <-----这里
cout << "the list's  numbers" << endl;
while(cin >> ival)
ilst.push_back(ival); //<-------这里
vector <int> ::const_iterator vecit = ivec.begin();
list  <int> ::const_iterator lstit = ilst.begin();
if(ilst.size() != ivec.size())
{
cout << "they are not same" << endl;
return 0;
}
else
{
for( ; vecit != ivec.end(), lstit != ilst.end(); ++vecit, ++lstit)
{
if(*vecit != *lstit)
{
cout << "they are not same" << endl;
return 0;
}
}
cout << "they are same!" << endl;
}
return 0;
}``````
Lynn_Ran 2008-03-13
• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout <<"the vetor's numbers" <<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();//<=========增加这个

cout <<"the list's  numbers" <<endl;
while(cin>> ival)
ilst.push_back(ival);//<=========容器写错了

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout <<"they are not same" <<endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout <<"they are not same" <<endl;
return 0;
}
}
cout <<"they are same!" <<endl;
}
return 0;
}
``````
Lynn_Ran 2008-03-13
• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout <<"the vetor's numbers" <<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();//<=========增加这个

cout <<"the list's  numbers" <<endl;
while(cin>> ival)
ilst.push_back(ival);//<=========容器写错了

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout <<"they are not same" <<endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout <<"they are not same" <<endl;
return 0;
}
}
cout <<"they are same!" <<endl;
}
return 0;
}``````
Lynn_Ran 2008-03-13
• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout <<"the vetor's numbers" <<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();//<=========增加这个

cout <<"the list's  numbers" <<endl;
while(cin>> ival)
ilst.push_back(ival);//<=========容器写错了

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout <<"they are not same" <<endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout <<"they are not same" <<endl;
return 0;
}
}
cout <<"they are same!" <<endl;
}
return 0;
}
``````
Lynn_Ran 2008-03-13
• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout <<"the vetor's numbers" <<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();//<=========增加这个

cout <<"the list's  numbers" <<endl;
while(cin>> ival)
ilst.push_back(ival);//<=========容器写错了

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout <<"they are not same" <<endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout <<"they are not same" <<endl;
return 0;
}
}
cout <<"they are same!" <<endl;
}
return 0;
}
``````
Lynn_Ran 2008-03-13
• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout < <"the vetor's numbers" < <endl;
while(cin> > ival)
ivec.push_back(ival);

cin.clear(); //记得把输入流清空下

cout < <"the list's  numbers" < <endl;
while(cin> > ival)
ilst.push_back(ival); //这里的ivec.push_back(ival); 写错了

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout < <"they are not same" < <endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout < <"they are not same" < <endl;
return 0;
}
}
cout < <"they are same!" < <endl;
}
return 0;
}
``````
jianfengshxy 2008-03-13
• 打赏
• 举报

jianfengshxy 2008-03-13
• 打赏
• 举报

jianfengshxy 2008-03-13
• 打赏
• 举报

jianfengshxy 2008-03-13
• 打赏
• 举报

• 打赏
• 举报

``````
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main()
{
vector <int>  ivec;
list <int>    ilst;
int ival;

cout <<"the vetor's numbers" <<endl;
while(cin>>ival)
ivec.push_back(ival);

cin.clear();//<=========增加这个

cout <<"the list's  numbers" <<endl;
while(cin>> ival)
ivec.push_back(ival);

cin.clear();

vector <int> ::const_iterator vecit=ivec.begin();
list  <int> ::const_iterator lstit=ilst.begin();

if(ilst.size()!=ivec.size())
{
cout <<"they are not same" <<endl;
return 0;
}
else
{   for(;vecit!=ivec.end(),lstit!=ilst.end();++vecit,++lstit)
{
if(*vecit!=*lstit)
{  cout <<"they are not same" <<endl;
return 0;
}
}
cout <<"they are same!" <<endl;
}
return 0;
}
``````

6.3w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等
c++ 技术论坛（原bbs）

2008-03-13 01:31

1. 请不要发布与C++技术无关的贴子
2. 请不要发布与技术无关的招聘、广告的帖子
3. 请尽可能的描述清楚你的问题，如果涉及到代码请尽可能的格式化一下