Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;而循环会无缘无故中断 #包括 #包括 使用名称空间std; int main(){ 弦元音[]={“b”、“c”、“d”、“f”、“g”、“h”、“j”、“k”、“l”、“m”、“n”、“p”、“q”、“r”、“s”、“t”、“v”_C++_String - Fatal编程技术网

C++ C++;而循环会无缘无故中断 #包括 #包括 使用名称空间std; int main(){ 弦元音[]={“b”、“c”、“d”、“f”、“g”、“h”、“j”、“k”、“l”、“m”、“n”、“p”、“q”、“r”、“s”、“t”、“v”

C++ C++;而循环会无缘无故中断 #包括 #包括 使用名称空间std; int main(){ 弦元音[]={“b”、“c”、“d”、“f”、“g”、“h”、“j”、“k”、“l”、“m”、“n”、“p”、“q”、“r”、“s”、“t”、“v”,c++,string,C++,String,C++;而循环会无缘无故中断 #包括 #包括 使用名称空间std; int main(){ 弦元音[]={“b”、“c”、“d”、“f”、“g”、“h”、“j”、“k”、“l”、“m”、“n”、“p”、“q”、“r”、“s”、“t”、“v”、“w”、“z”}; 字符串a; 而(a!=“退出!”){ int b=1; cin>>a; 对于(int i=0;i4&&a.substr(a.length()-3)=元音[i]+“或”){ a[a.length()-2]=“o”; a[a.

C++;而循环会无缘无故中断
#包括
#包括
使用名称空间std;
int main(){
弦元音[]={“b”、“c”、“d”、“f”、“g”、“h”、“j”、“k”、“l”、“m”、“n”、“p”、“q”、“r”、“s”、“t”、“v”、“w”、“z”};
字符串a;
而(a!=“退出!”){
int b=1;
cin>>a;
对于(int i=0;i<20;i++){
如果(a.length()>4&&a.substr(a.length()-3)=元音[i]+“或”){
a[a.length()-2]=“o”;
a[a.length()-1]=“u”;
a+=‘r’;
试试这个:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    string vowel[] = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "z"};
    string a;

    while (a != "quit!") {
        int b = 1;
        cin >> a;
        for (int i = 0; i < 20; i++) {

            if (a.length() > 4 && a.substr(a.length() - 3 ) == vowel[i] + "or") {
                a[a.length() - 2] = 'o';
                a[a.length() - 1] = 'u';
                a += 'r';
                cout << a << "\n";
                b = 0;
                break;
            }
            //cout << i;
        }

        if (b == 1) {
            cout << a << "\n";
        }
    }
}
#包括
#包括
#包括
使用名称空间std;
bool endswith(常量字符串&a、字符串b){
返回(b==a.substr(a.length()-b.length());
}
布尔同调(字符c){
向量元音={a',e',i',o',u',y'};
for(size_t i=0;i<元音.size();i++){
if(元音[i]==c)
返回false;
}
返回true;
}
int main(){
字符串a;
而(a!=“退出!”){
cin>>a;
if((a.length()>4)和&isconant(a[a.length()-3])&&endswith(a,string(“or”))
a=a.substr(0,a.length()-2)+“我们的”;

你说的是while循环还是for循环?因为你的描述现在说的是for循环,但是你的标题是指外部while循环。你的程序可能会崩溃,因为你的数组少于20个元素。噢,哈哈,非常感谢,所以请使用
vector
,然后使用
size()
方法。
字符串元音[]
:你是说
辅音
?这是一个只使用代码的答案。因为它们有令人讨厌的倾向,所以你应该避免使用它们。你可以通过解释问题是什么以及如何解决来解决这个问题。
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool endswith(const string& a, string b) {
   return (b == a.substr(a.length() - b.length()));
}

bool isconsonant(char c) {
   vector<char> vowels = { 'a', 'e', 'i', 'o', 'u','y' };

   for (size_t i=0; i < vowels.size(); i++) {
      if (vowels[i] == c)
         return false;
   }

   return true;
}

int main() {
   string a;

   while (a != "quit!") {
      cin >> a;

      if ((a.length() > 4) && isconsonant(a[a.length()-3]) && endswith(a, string("or")))
            a = a.substr(0, a.length() - 2) + "our";

      cout << a << "\n";
   }
}