如何使用队列将字符串转换为大写
How to convert a string to uppercase using a Queue?
#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(((不能将它们放在大写。
提示:"编写一个程序,从用户那里获取一个句子(字符串(,并将其放入一个字符队列中。然后,程序应该将每个字符出列,将其转换为大写,并将结果存储为一个句子(字符串(。打印该过程的结果";。
您可以通过以下方式执行此操作。
#include<iostream>
#include<queue>
#include<string> // probally not needed
#include<cctype>
using namespace std;
int main()
{
queue <char> str; //make it char queue
cout << "Please enter a string." << endl;
string temp, result = "";
getline (cin, temp); //grabs string, including spaces
if(temp != "") // checks if string is empty
{
// push each character into queue
for(int i = 0; i < temp.size(); i++) // suppose to go through
{
str.push(temp[i]);
}
while(!str.empty()) //take a char from queue and do the task pop them.
{
char tm = str.front();
str.pop();
tm = tm-32; // making lower to upper
result = result+tm;
}
}
else
{
exit(0); // exits the program if string is empty
}
cout << result; // suppose to display queue, that should be in
//upper case form.
return 0;
}
相关文章:
- wcstombs_s(),转换字符串的长度
- 使用 CStringW/CStringA 和 CT2W/CT2A 转换字符串有什么区别?
- 无法转换字符串插入函数的参数
- 转换字符串向量:基于先前的值跳过元素
- 从中间器转换字符串不起作用,出了什么问题?
- 失败的证明转换字符串到枚举类
- 如何使用正则表达式和提升转换迭代器标记和转换 c 字符串
- 使用java jni时转换字符串类型
- 如何避免在转换字符串令牌流时重复istringstream构造
- 阿托伊未正确转换字符串
- C++,转换字符串,使连续下划线序列变为单个下划线
- 使用长算术转换字符串
- 转换字符串十进制数时的精度
- 将词法转换字符串提升为双精度
- 使用marshal_as函数转换字符串的性能
- C++不会从数据转换字符串
- 无论如何,在c++ /Qt中转换字符串到结构中的字段
- C++ 隐式类型转换字符串 -> int?
- 转换字符串到浮点数,c++实现
- 用于转换字符串大小写的函数