One more thing, to answer the original question, "Where am i wrong?", the original code was attempting out of bounds access to the string. You can show this by replacing pass[] with pass.at(). They both do effectively the same thing, but the at() member function does range checking and generates an exception if the subscript is out of range.
If you run this and simply press enter, you will see an output like this:
Enter password
pass = length = 0
Run it again and press any other key, you may see something like this - depending on compiler.
Enter password*terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
(msg1028200)'s code is supposed to fail and cause a runtime exception. Chervil's first post (msg1028137) is what works on my machine (MinGW g++ 7.1.0, Windows 10), and should work on your machine (if Windows and MinGW), too.
Edit: I see you said you are using the pop_back code.
Are you sure you're running the code verbatim?
Are you getting any compiler warnings?
What name+version is the compiler you downloaded with Code::Blocks?
Is the program crashing, or does it just hang at getch()?
An alternative to the ancient getch would probably have to come from a library that hides part of the console, such as ncurses. But I am not familiar with, so sorry if this post is useless.