vector<string>::size_type与string::size_type
来源:互联网 发布:伊朗的土地改革知乎 编辑:程序博客网 时间:2024/04/29 11:17
#include <iostream>#include <vector>#include <string>using namespace std;int main(){ vector<string> svec; string str; cout << "Enter text:" << endl; while (cin>>str) svec.push_back(str); if (svec.size() == 0) { cout << "No string?!" << endl; return -1; } cout << "Transformed elements from the vector:"<< endl; for (vector<string>::size_type ix=0; ix!=svec.size()-1;++ix)//for (string::size_type ix=0; ix!=svec.size()-1;++ix)// vector<string>改成string,编译、执行都正常 {for (vector<string>::size_type index = 0;index != svec[ix].size();++index)//for(string::size_type index = 0;index != svec[ix].size();++index)// vector<string>改成string,编译、执行都正常 if(islower(svec[ix][index])) svec[ix][index]=toupper(svec[ix][index]);cout << svec[ix] << " "; if ((ix+1) % 8 ==0) cout << endl;cout << "Transformed elements from the vector:" << endl; } return 0;}
#include <iostream>#include <vector>#include <string>#include <typeinfo>using namespace std;int main(){ cout<<"The sizeof string::size_type is "<<sizeof(string::size_type)<<endl;cout<<"The type of string::size_type is "<<typeid(string::size_type).name()<<endl; cout<<"The type of vector<string>::size_type is "<<sizeof(vector <string>::size_type)<<endl;cout<<"The type of vector<string>::size_type is "<<typeid(vector <string>::size_type).name()<<endl; return 0;}