永发信息网

关于C++中的vector语句的相关问题

答案:2  悬赏:10  手机版
解决时间 2021-01-31 12:35
  • 提问者网友:wodetian
  • 2021-01-31 05:53
题目是:从cin读入一组词并把它们存入一个vector对象,然后设法把所有词都改写为大写形式。输出改变后的结果,每个词占一行。

我输出没有东西!

#include
#include
#include
using namespace std;
int main()
{
string a;
vector b;
while (cin >> a){
b.push_back(a);
}
for (auto &d : a)
d = toupper(a);
for (auto d : b)
cout << d << " " << endl;
system("pause");
return 0;
}
希望详细,谢谢,
最佳答案
  • 五星知识达人网友:有你哪都是故乡
  • 2021-01-31 06:03
#include 
#include 
#include 

using namespace std;

int main(){

vector V;

for(string t; cin >> t; V.push_back(t));

for(auto i=V.begin(); i!=V.end(); ++i)
for(auto j=i->begin(); j!=i->end(); ++j)
*j = toupper(*j);  

for(auto i=V.begin(); i!=V.end(); ++i)
cout << *i << endl;

return 0;
}
全部回答
  • 1楼网友:等灯
  • 2021-01-31 07:03
#include <iostream> #include <vector> using namespace std; int main() {  vector <double> salaries;  bool more = true;  while(more)  {   double s;   cout << " please enter a salary .0 to quit:";   cin >> s;   if( s == 0)    more = false;   else    salaries.push_back(s);  }  double highest = salaries[0];  int i;  for (i = 1;i<salaries.size();i++)   if(salaries[i]>highest)    highest = salaries[i];   for (i = 0 ; i< salaries.size(); i++)   {    if ( salaries[i] == highest)     cout << "highest salary: " << salaries[i] << endl;   }  return 0; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯