为什么我在C ++中收到std :: out_of_range错误?

时间:2019-05-11 07:31:56

标签: c++ string

当我在此在线编译器上运行它时,它可以工作 https://www.onlinegdb.com/online_c++_compiler

尽管当我在Windows visual studio上运行它时,它在第13行给了我一个错误

#include <iostream>
#include <string>
using namespace std;

int isUnique(string testing) {
    int y = 0;
    int z = 1;
    int x = testing.capacity() - 1;


    while (y < x) {
        while (z < x) {
            if (testing.at(y) == testing.at(z)) {
                std::cout << "The string does not have all unique characters";
                exit(1);
            }
            z++;
        }
        y++;
        z = y + 1;
    }

    std::cout << "The string has all unique characters";
    std::cout << x;
    return 0;
}

int main()
{
    string x;
    getline(cin, x);
    isUnique(x);
    std::cout << "Hello World";
    return 0;
}

0 个答案:

没有答案