您的位置:首页 > 其它

cin流的状态和缓存刷新问题

2008-03-14 09:51 232 查看

#include "stdafx.h"


#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(),' ');//此处关键


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;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: