需要将CString类型对象转换为整型,存到数组里面。
例如,CString类对象为"1234",需要转换为数组point,数组成员为1,2,3,4
下面是我写的代码程序
         CFileDialog fileDlg(TRUE);
CString str;
int *m_point=new int[1000];
m_point=NULL;
fileDlg.m_ofn.lpstrTitle=_T("打开心电文件");
fileDlg.m_ofn.lpstrFilter=_T("Text File(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0");
if(IDOK==fileDlg.DoModal())
{
CStdioFile file(fileDlg.GetPathName(),CFile::modeRead);
while(file.ReadString(str))
{
str.GetBufferSetLength(1000);
result+=str;
}
for(int i=0;i<1000;i++)
{
   m_point[i]=_tcstol((const wchar_t*)result.GetAt(i),NULL,10);
}
result.ReleaseBuffer();
delete fileDlg;
delete[] m_point;
m_point=NULL;
file.Close();
}
端点调试之后,大致是m_point[i]=_tcstol((const wchar_t*)result.GetAt(i),NULL,10);
出了问题,但是具体怎么改,还请大家帮忙

解决方案 »

  1.   

    _tcstol 是将字符串转化为long类型的哦
    你要留意你的工程是for为unicode.
      

  2.   

    vector<string> domains;
    int xxx[20];
    _domains.push_back("+0.6");
    _domains.push_back("+0.4");
    _domains.push_back("+0.2");
    _domains.push_back("+0.0");
    _domains.push_back("-0.2");
    _domains.push_back("-0.4");
    _domains.push_back("-0.6");for( size_t   i =  0; i <_domains.size(); ++i) 
    {
    xxx[i] = _atoi((LPCTSTR)_domains[i].c_str()); 
    }
    完!
      

  3.   

    调试的结果,是:
    有未经处理的异常: 0xC0000005: 读取位置 0x0000002d 时发生访问冲突
    应该是数组或者指针的问题吧,
      

  4.   

    读一个WCHAR出来, 然后变换一个0 ~ 9的数值...有这么复杂?
      

  5.   

    _tcstol((const wchar_t*)result.GetAt(i),NULL,10);是不是写错了, GetAt是领取一个wchar_t出来, 而不是wchar_t*, 它是一个16位的字符, 不是一个字符串, 把字符变成数值不要用字符串的操作. 直接把值减去ascii表当中对应的值就变换成数值了. 或者采用查表的方式把 0 ~ 9 对号入座就可以了
      

  6.   

    不是通过强制转换为const wchar_t*类型了嘛,支持强制转换的啊,应该不是这个部分的问题吧,
      

  7.   

    int *m_point=new int[1000];
    m_point=NULL;你怎么又变成NULL了?把标红的那句去掉!