【发布时间】:2021-05-16 06:52:10
【问题描述】:
#include<iostream>
#include<queue>
#include<string> // probally not needed
#include<cctype>
using namespace std;
int main()
{
queue <string> str; // i created some kind of vector queue
cout << "Please enter a string." << endl;
string temp;
cin >> temp; // grabs the string
if(temp != "") // checks if string is empty
{
str.push(temp); // pushes it onto queue
for(int i = 0; i < temp.size(); i++) // suppose to go through
//each element in queue
{
//str.pop(temp); /pops an element as requied by assignment
toupper(i); // suppose to turn each letter upper case
}
}
else
{
exit(0); // exits the program if string is empty
}
cout << temp; // suppose to display queue, that should be in
//upper case form.
return 0;
}
我对编程还是很陌生,我不知道将队列实现为字符串。问题是 for 循环没有遍历每个字母,因此 (toUpper()) 不能将它们大写。
提示:“编写一个程序,从用户那里获取一个句子(字符串)并将其放入字符队列中。然后程序应该将每个字符出列,将其转换为大写并将结果存储为一个句子(字符串) . 打印这个过程的结果”。
【问题讨论】:
-
“字符队列”是
queue<char>,而不是queue<string>。
标签: c++ string data-structures ide queue