小编Gna*_*Rad的帖子

C++ While循环不重新分配字符串值

我创建了一个程序来计算提供的字符串中元音的数量.它正确计算元音,并在用户提供"y"或"Y"时重复.但是,当它重复时,它会自动将""分配给我试图使用的C字符串.

int main()
{
    //Creating repeating decision
    char answer = 'y';

    while ((answer == 'y') || (answer == 'Y'))
    {

        //declaring our C-String
        char ourString[81] = "Default";

        //Prompting user for a string, storing it as a C-String
        std::cout << "Please enter a string!(Less than 80 characters please.)\n";
        std::cin.getline(ourString, 81);

        //Using a loop to count the amount of vowels
        int ourNum = 0;
        int vowels = 0;

        while (ourString[ourNum] != '\0')
        {
            switch (ourString[ourNum]) {
            case 'a':
            case 'A':
            case 'e': …
Run Code Online (Sandbox Code Playgroud)

c++ iostream input c-strings while-loop

3
推荐指数
1
解决办法
73
查看次数

标签 统计

c++ ×1

c-strings ×1

input ×1

iostream ×1

while-loop ×1