C++ 字符数组复制错误

C++ 字符数组复制错误,c++,arrays,character,C++,Arrays,Character,我的问题是,当内部for循环退出并返回到外部for循环时,它将停止向字符串指针pstrDestination添加字符。有人能向我解释一下,我并没有终止字符数组,所以它仍然应该写,不是吗 // Does it match if (strcmp(strCompareString, pstrToFind) == 0) { // Reset the index of the found letter intFoundLetterIndex = (intFoundLetterIndex

我的问题是,当内部for循环退出并返回到外部for循环时,它将停止向字符串指针pstrDestination添加字符。有人能向我解释一下,我并没有终止字符数组,所以它仍然应该写,不是吗

// Does it match
if (strcmp(strCompareString, pstrToFind) == 0)
{

    // Reset the index of the found letter
    intFoundLetterIndex = (intFoundLetterIndex - intCompareIndex);

    // Add the characters from source to destination.
    for (intSourceIndex = 0; intSourceIndex < intSourceLength; intSourceIndex += 1)
    {

        pstrDestination[intDestinationIndex] = pstrSource[intSourceIndex];
        intDestinationIndex += 1;

        // Are we at the beginning of the target word
        if (intSourceIndex == intFoundLetterIndex)
        {

            // Add the replacement characters to the destination.
            for (intNewIndex = 0; intNewIndex < intReplaceWithLength; intNewIndex += 1)
            {

                pstrDestination[intDestinationIndex - 1] = pstrReplaceWith[intNewIndex];
                intDestinationIndex += 1;

            }

            intSourceIndex += intToFindLength;
        }

    }

}
//它匹配吗
if(strcmp(strCompareString,pstrofind)==0)
{
//重置找到的字母的索引
intFoundLetterIndex=(intFoundLetterIndex-intCompareIndex);
//将字符从源添加到目标。
对于(intSourceIndex=0;intSourceIndex
我认为

intDestinationIndex - 1;
应该是这样的:

intDestinationIndex -= 1;

我能想到的最好的办法是,VisualStudio2013 IDE正试图给我一个大大的拥抱。 它正在为我终止字符串。 如果我将索引后退1步,并将数组中的点设置为“”。然后循环按预期执行,因为我重写了终止符

在内部循环之后,我添加了

pstrDestination[intDestinationIndex - 1] = ' ';

我不明白你的要求。您是否已经使用调试器逐步完成了代码?您应该了解变量递增和递减的
++
--
intDestinationIndex-1你认为这个语句实际上是做什么的?是的,好的,我正在替换字符串中的一个单词,但是我使用的不是内置的字符串数据类型,而是一个字符数组。当我到达要替换的单词的起始点时,我会用一个新词或短语替换它。但当替换完成后,我退出内部for循环。外部for循环像它应该的那样快速运行,但它停止向pstrDestination添加字符,它好像被终止了,但我没有终止字符串。continue语句是多余的。