C++ 如何更正此分配错误
我假设创建一个嵌套循环,循环遍历一个动态分配的数组(story),找到字符“*”,并用另一个动态分配的数组(用户输入)的信息填充该字符所在的位置。然后将此替换信息存储在名为body to be cout的新动态分配数组中。 以下是错误:C++ 如何更正此分配错误,c++,nested-loops,dynamic-arrays,C++,Nested Loops,Dynamic Arrays,我假设创建一个嵌套循环,循环遍历一个动态分配的数组(story),找到字符“*”,并用另一个动态分配的数组(用户输入)的信息填充该字符所在的位置。然后将此替换信息存储在名为body to be cout的新动态分配数组中。 以下是错误: 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1>
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
1>带有
1> [
1> _Elem=char,
1> _Traits=std::char_Traits,
1> _Alloc=std::分配器
1> ]
没有可以进行此转换的上下文
谁能告诉我我做错了什么?
这是我的密码:
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];
}
}
}
}
void create_story(字符串和用户输入、字符串*story、int num_行、,
字符串**正文)
{
*body=新字符串[num_行];
for(int i=0;i cout这段代码中有几个逻辑错误
下一行对程序的状态没有影响(没有副作用)
body[i];
由于索引i
出现在不等式的两侧,因此下一行极不可能正确终止
for(int i=0;i