Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ I cannot solve this error

Hello I'm fairly new to programming and trying to code a project I came across this error and after a few weeks I cannot do anything about it. Does anyone know what I have to change?

Error says: "An invalid parameter was passed to a function that produces an unrecoverable error if invalid parameters are specified."
C++:
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    string posCorrecta;
    string posIncorrecta;
    string palabra2;
    string wordle = "fuera";
    string palabra = "fuese";

    bool acierto = true;

    for (int i = 0; i < 5; i++) {

        if (palabra[i] == wordle[i]) {

            posCorrecta[i] = palabra[i];

        }
        else {

            for (int k = 0; k < 5; k++) {

                if (palabra[i] == wordle[k]) {

                    posIncorrecta[i] = palabra[i];

                }

            }

        }
        
    }


    if (palabra == wordle) {

        acierto = true;

    }

    for (int j = 0; j < 5; j++) {

        if (posCorrecta[j] == palabra[j]) {

            palabra2 = palabra2 + "[" + posCorrecta[j] + "]";

        }
        else {

            if (posIncorrecta[j] == palabra[j]) {

                palabra2 = palabra2 + "(" + posIncorrecta[j] + ")";

            }
            else {

                palabra2 = palabra2 + palabra[j];

            }

        }

    }

    palabra = palabra2; 

};

Thanks for everything.
 
You might want to place this error message in some context. I don't think it originates from the code you posted here, as it does not even contain a function call ! Actually the code compiles fine in Visual Studio, but when executing it breaks at line 21 with Exception: subscript out of range. You are treating a C++ string object as if it were a C character array.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom