标签:iterator int 31 cin value CMyistream inputStr
1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 template <class T> 6 class CMyistream_iterator 7 { 8 private: 9 istream& in; 10 T value; 11 public: 12 CMyistream_iterator(istream& _in):in(_in){ 13 cin >> value; 14 } 15 T operator*(){ 16 return value; 17 } 18 void operator++(int){ 19 in >> value; 20 } 21 }; 22 23 24 25 int main() 26 { 27 int t; 28 cin >> t; 29 while( t -- ) { 30 CMyistream_iterator<int> inputInt(cin); 31 int n1,n2,n3; 32 n1 = * inputInt; //读入 n1 33 int tmp = * inputInt; 34 cout << tmp << endl; 35 inputInt ++; 36 n2 = * inputInt; //读入 n2 37 inputInt ++; 38 n3 = * inputInt; //读入 n3 39 cout << n1 << " " << n2<< " " << n3 << " "; 40 CMyistream_iterator<string> inputStr(cin); 41 string s1,s2; 42 s1 = * inputStr; 43 inputStr ++; 44 s2 = * inputStr; 45 cout << s1 << " " << s2 << endl; 46 } 47 return 0; 48 }
1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 template <class T> 6 class CMyistream_iterator 7 { 8 private: 9 istream& in; 10 T value; 11 public: 12 CMyistream_iterator(istream& _in):in(_in){ 13 cin >> value; 14 } 15 T operator*(){ 16 return value; 17 } 18 CMyistream_iterator operator++(int){ 19 in >> value; 20 return *this; 21 } 22 }; 23 24 25 26 int main() 27 { 28 int t; 29 cin >> t; 30 while( t -- ) { 31 CMyistream_iterator<int> inputInt(cin); 32 int n1,n2,n3; 33 n1 = * inputInt; //读入 n1 34 int tmp = * inputInt; 35 cout << tmp << endl; 36 inputInt ++; 37 n2 = * inputInt; //读入 n2 38 inputInt ++; 39 n3 = * inputInt; //读入 n3 40 cout << n1 << " " << n2<< " " << n3 << " "; 41 CMyistream_iterator<string> inputStr(cin); 42 string s1,s2; 43 s1 = * inputStr; 44 inputStr ++; 45 s2 = * inputStr; 46 cout << s1 << " " << s2 << endl; 47 } 48 return 0; 49 }
标签:iterator,int,31,cin,value,CMyistream,inputStr
来源: https://www.cnblogs.com/balabalabubalabala/p/16691299.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。