您的位置:首页 > 其它

标准库容器 vector 中string的字符 处理

2013-02-07 15:17 232 查看
相关知识点:

size_type

vector
和许多标准库类一样都定义了一些配套类型(companion type),通过这些配套类型,能使标准库的使用与机器无关(machine-independent).

处理处于容器中的字符串的字符类型于对二维数组中元素的操作。

//modified by quanspace 2013-02-06 18:16
/* Read some text into a vector, storing each word in the input as an
*element in the vector.  transform each word into uppercase letters.
*print eight words to a line.
*/
# include <iostream>
# include <vector>
# include <string>
using namespace std;
int main(){
vector<string> word_vec;
string word;
cout<<"Input some text :"<<endl;
while(cin>>word){
if(word == "esc!!!") break;
word_vec.push_back(word);
}
for(vector<string>::size_type i = 0; i != word_vec.size(); ++i){
for(int j = 0; j != word_vec[i].size(); ++j)
word_vec[i][j] = toupper(word_vec[i][j]);
if(i%8 == 0)
cout<<endl;
cout<<word_vec[i]<<" ";
}
return 0;
}




参考 C++ primer 4 edition exercises 3.14
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐