new了以后delete失败,以及MessageBox输出Unicode有关问题

new了以后delete失败,以及MessageBox输出Unicode问题
下面代码在VS2010下编译 控制台程序 空项目 主要有两个问题 第一张图是MessageBox报的 第二张图是delete报的
以下代码主要用于对text文件中的文本内容提取,保存到数组中。以下代码为测试功能的。
编写这段代码主要为了实现分词功能,将文本文件中一行的内容读到数组中从数组中的最后一个元素开始实现对一行内容的逆向匹配。


下面是我的代码:
C/C++ code

#include <iostream>
#include <fstream>
#include <afx.h>
#include <stdio.h>
#include <afxwin.h> //框架窗口的头文件

using namespace std;

class WordNode
{
    public:
        DWORD wordCount;
        CString word;

};

int main()
{
    //ifstream rf("1.txt",ios::in);
    CString str;
    FILE *file = fopen("1.txt","r");
    int length;//数组长度
    TCHAR *lptchar;//动态数组指针

    if(!file)
        return -1;
    else
    {
        CStdioFile cfile(file);
        cfile.SeekToBegin();
        while(!feof(file))
        {
            cfile.ReadString(str);
            length = str.GetLength();
            lptchar = new TCHAR(length + 1);
        /*    HGLOBAL hMem = GlobalAlloc(0,(length+1)*2);
            if(!hMem)
                return -1;*/

        /*    LPVOID lptchar = GlobalLock(HGLOBAL(hMem));
            
            if(!lptchar)
                return -1;*/

            //delete[] lptchar;
            memset(lptchar,0,length+1);
            
            wcscpy(lptchar,str.GetBuffer(length));
            
//            delete[] lptchar;

            for(int i = length - 1;i >= 0;i--)
            {
            //    ::MessageBoxA(0,LPCSTR(lptchar[i]),"test",MB_OK);//这里使用MessageBox输出为什么会报错?
                wcout<<lptchar[i];//使用wcout却能够输出。
                str.ReleaseBuffer(length);
                delete[] lptchar;//delete 为什么会报错?
                /*GlobalUnlock(hMem);

                if(!GlobalFree(lptchar))
                    return 0;
                else
                    return -1;*/

                return 0 ;
            }
        }
    }
    
    

    //::AfxMessageBox(str,MB_OK,0);

    return 0;
}





图一:



图二:



------解决方案--------------------
1. MessageBox出错原因是LPCSTR(lptchar[i]) 应该是 LPCSTR(&lptchar[i])

2. 你将wcout<<lptchar[i]; 这一句注释掉 看出不出现错误。
------解决方案--------------------
lptchar = new TCHAR(length + 1);
-》
lptchar = new TCHAR[length + 1];