【发布时间】:2020-09-28 07:51:00
【问题描述】:
有没有其他方法可以改变6个字母单词的第一个字母和最后一个字母?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
cout<< "\nEnter a 6 letter word or numbers: ";
cin>>word;
word[0]++;
word[5]++;
cout << "Result: " << word << endl;
return 0;
}
【问题讨论】:
-
什么意思?是的,还有其他方法。你现在的使用方式有什么问题?
-
有人建议我使用 if/else 或 setw,这可能吗?
-
@idclev463035818 我需要 2-3 种方法。这是我想到的最简单的一个。
-
嗯,对于初学者,您可以使用
if来检查单词是否已被实际阅读以及是否至少包含 6 个字母。你已经被介绍给迭代器了吗?std::string的成员函数你知道多少? -
您能说明一下您要达到的目标吗?
标签: c++