0

I am suppose to create a nested loop that cycles through a dynamically allocated array (story) find the char ''*', and fill in the position where this char is with information from the other dynamically allocated array (user_input). Then store this replacement information in a new dynamically allocated array called body to be cout. Here is the error:

1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
There is no context in which this conversion is possible

can anyone tell me what I'm doing wrong? Here is my code:

void create_story(string & user_inputs, string *story, int num_lines,
        string **body)
{
    *body = new string[num_lines];

    for (int i = 0; i < story[i].length; i++)
    {
        if (story[i] == "*")
        {
            body[i];
        }

        for (int j = 0; j < story[i].length(); j++)
        {
            if (story[i][j] == '*')
            {
                cout << "I found it at character number: " << i;
                *body[i] += user_inputs;
            }
            else
            {
                body[i] += story[i][j];
            }
        }
    }
}
xmoex
  • 2,602
  • 22
  • 36

1 Answers1

0

There are several logical errors in this code.

  1. The following line has no effect on the state of the program (no side effect).

    body[i];

  2. The following line is extremely unlikely to terminate correctly since the index i appears on both sides of the inequality.

    for (int i=0; i<story[i].length; i++)

  3. The above line may not compile since it compares an int and a member function (length).

  4. The following line tests whether the entire i-th line is simple a single star.

    if(story[i]=="*")

I am sure there are other issues as well. You should start with less code and see if you can get the assignment done in steps instead of trying to do it all at once. It will be easier to understand.

Dwayne Towell
  • 8,154
  • 4
  • 36
  • 49