How to solve the " Assertion ‘__pos <= size()’ failed" in app which have to recognizes the sex after the name?

  c++

Hi I learn c ++ acutally write a program that is to determine on the last letter in the Polish name, whether it is a female or male name. Fun fact: all of the female names in Polish ends with the letter "a".

#include <iostream>
using namespace std
int main()
{
   string imie;
    cout<<"Podaj imie: ";
    cin>> imie;

    int dlugosc=imie.length();

    if (imie[dlugosc-1]=='a'||'A')

        cout<<"Jestes kobieta";

    else cout<<"Jestes mezcyzna";

    return 0;
}

After entering this code, the application normally fires but, if you type a female or male name, this error pops up.

/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libstdc++-v3/include/bits/basic_string.h:1067: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]: Assertion '__pos <= size()' failed.

What should I change in this app to work properly?

Source: Windows Questions C++

One Reply to “How to solve the " Assertion ‘__pos <= size()’ failed" in app which have to recognizes the sex after the name?”

LEAVE A COMMENT