郁闷!这个C++的题目谁帮我看下。

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:08:11
读入一段文本到vector 对象,每个单词存储为vector 中的一个元素。把vector
对象中每个单词转化为大写字母。输出vector 对象中转化后的元素,每8 个单
词为一行输出。

#include<iostream>
#include<vector>
#include<cctype>
#include<string>
using namespace std;
int main()
{
cout<<"请输入:"<<endl;
vector<string>ru;
string a;
while(cin>>a){
ru.push_back(a);}
for(string::size_cype b=0;b<ru.size();++b){
cout<<toupper(ru[b])<<" ";
if(b%8==0)
cout<<endl;
}
return 0;
}
为什么会报错??? 我把STRING类型改位CHAR就可以。。

郁闷
这个问题你刚才问过来吧

你这里面有两个错误
1:
string::size_type, 你写成string::size_cype
2,
toupper()不能用来转化字符串

我给你改了下,你看看

#include<iostream>
#include<vector>
#include<cctype>
#include<string>
using namespace std;
int main()
{
cout<<"请输入:"<<endl;
vector<string>ru;
string a;
while(cin>>a){
ru.push_back(a);}
for(string::size_type b=0;b<ru.size();++b){
//--------------------------------------------------------
string s = ru[b];
for (string::size_type index = 0; index != s.size(); ++index)
s[index] = toupper(s[index]);
cout <<s<<"\t";
//-------------以上是小写转化为大写
if(b%8==0)
cout<<endl;
}
return 0;
}

toupper()的参数问题
toupper要求的是一个int作参数,而你给它的是个string

可以这样写

#include<iostream>