Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do you insert and integer in a string array?

+2 votes
asked Mar 9 by Ryan Maiden (170 points)
This has worked for several of my classmates. It runs with no error, but ends at  if (arr [r][c] == "[L]").

What else can I use to keep the brackets, but replace L with an incremented number?

int num=1;
for (int r = 0; r <= ROWS; r++)
    {
        for (int c = 0; c <= COLS; c++)
        {
            if (arr [r][c] == "[L]")
            {
                string str = to_string(num++);
                string s = "[" + str + "]";
                arr[r][c] = s;
            }
        }
    }

1 Answer

0 votes
answered Mar 14 by Peter Minarik (63,140 points)

This should work

int number = 3; // use your own value
// ...
if (arr [r][c] == "[" + to_string(number) + "]")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...