65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
int main()
{
vector<string> svec;
string str;
// 读入文本到vector 对象
cout << "Enter text(Ctrl+Z to end):" << endl;
while (cin>>str)
svec.push_back(str);
//将vector 对象中每个单词转化为大写字母,并输出
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(); ++ix) {
for (string::size_type index = 0; index != svec[ix].size();
++index)
if (islower(svec[ix][index]))
//单词中下标为index 的字符为小写字母
svec[ix][index] = toupper(svec[ix][index]);
cout << svec[ix] << " ";
if ((ix + 1) % 8 == 0)//每8 个单词为一行输出
cout << endl;
}
return 0;
}习题解答上的答案#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> vContent;
string word;
while(cin>>word)
{
transform(word.begin(),word.end(),word.begin(),toupper);
vContent.push_back(word);
}
int count =1;
for(vector<string>::size_type i=0;i<vContent.size();i++)
{
cout<<vContent[i]<<" ";
if(count++%8 ==0)
{
cout<<endl;
}
}
getchar();
return 0;
}#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
void main()
{
vector<string> vec;
char ch[20];
while(cin>>ch)
{
string str=ch;
vec.push_back(str);
}
for(int i=0;i<vec.size();i++)
for(int j=0;j<strlen(vec[i].data());j++)
{
if(islower(vec[i][j]))
vec[i][j]=toupper(vec[i][j]);
}
for(int k=0;k<vec.size();k++)
cout<<vec[k]<<endl;
}
abc
edf
dfe
^Z
^Z
ABC
EDF
DFE
Press any key to continue
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
int main()
{
vector<string> svec;
string word("wo ai ni ,888,777,666,baobei!!!");
for (string::size_type ix = 0; ix != word.size(); ++ix)
{
word[ix] = toupper(word[ix]);
}
cout << word << endl;
for (vector<string>::size_type ix2 = 0; ix2 != 1; ++ix2)
{
svec.push_back(word);
cout << svec[ix2] ;
}
cout << endl;
return 0;
}