关于CString和vector链表

LRYIVAN 2010-07-24 11:37:22
CString CImaManage::GetFileName(int i)
{
return v_FileName[i];
}

在调试这一段代码的时候,系统报错,并指向这一段,请问为什么。
_AFX_INLINE CStringData* CString::GetData() const
{ ASSERT(m_pchData != NULL); return ((CStringData*)m_pchData)-1; }


代码如下:
std::vector<CString> v_FileName
void CImaManage::SetFileName(CString str)
{
v_FileName.push_back(str);

}
CString CImaManage::GetFileName(int i)
{
return v_FileName[i];
}
ma.SetFileName(pPath);
DisPlay(ma.GetFileName(nIdex));
...全文
149 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
CloudmmFly 2010-07-25
  • 打赏
  • 举报
回复

就看ma 是不是=NULL就成了,DEBUG时,运行到那,鼠标放到ma上就显示了
hongya6088 2010-07-24
  • 打赏
  • 举报
回复
应该是断言错误,跟踪一下str的值是什么。
半刻沙漏 2010-07-24
  • 打赏
  • 举报
回复
估计是你断言的问题吧
LRYIVAN 2010-07-24
  • 打赏
  • 举报
回复
ma(对象)不是在创建的时候就会自动调用默认构造函数吗,它的意义就是引用成员函数吧
LRYIVAN 2010-07-24
  • 打赏
  • 举报
回复
怎么判断ma是否初始化成功,pPath是CString类型的
xiaohf702 2010-07-24
  • 打赏
  • 举报
回复
ma.SetFileName(pPath);恶意的猜想传的是个指针。
oyljerry 2010-07-24
  • 打赏
  • 举报
回复
ma是否初始化成功
LRYIVAN 2010-07-24
  • 打赏
  • 举报
回复
上网查了错误的原因说是空指针的问题,但是我已经用ma.SetFileName(pPath);给链表赋值了啊
LRYIVAN 2010-07-24
  • 打赏
  • 举报
回复
v_FileName {...}
std::vector<CString,std::allocator<CString> >::operator[] returned {"C:\Documents and Settings\one\桌面\bmp1\圆.bmp"}
这是对函数
void CImaManage::SetFileName(CString str)
{
v_FileName.push_back(str);

}
调试的结果
我不明白为什么v_FileName{...}没有赋值,但是std::vector<CString,std::allocator<CString> >::operator[] returned {"C:\Documents and Settings\one\桌面\bmp1\圆.bmp"}这个奇怪的东西就有赋值
LRYIVAN 2010-07-24
  • 打赏
  • 举报
回复
什么叫断言错误啊?数组越界又是怎么越界了?str的值是 {"C:\Documents and Settings\one\桌面\bmp1\圆.bmp"}
stonewater 2010-07-24
  • 打赏
  • 举报
回复
CString CImaManage::GetFileName(int i)
{
return v_FileName[i];
}

这个函数要先判断下i是否超过v_FileName.size();
雪影 2010-07-24
  • 打赏
  • 举报
回复
既然使用了stl vertor为什么还使用CString呢?
使用string不是更好?
#include <iostream>
#include <vector>
#include <string>

using namespace std;

main()
{
vector<string> SS;

SS.push_back("The number is 10");
SS.push_back("The number is 20");
SS.push_back("The number is 30");

cout << "Loop by index:" << endl;

int ii;
for(ii=0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}

cout << endl << "Constant Iterator:" << endl;

vector<string>::const_iterator cii;
for(cii=SS.begin(); cii!=SS.end(); cii++)
{
cout << *cii << endl;
}

cout << endl << "Reverse Iterator:" << endl;

vector<string>::reverse_iterator rii;
for(rii=SS.rbegin(); rii!=SS.rend(); ++rii)
{
cout << *rii << endl;
}

cout << endl << "Sample Output:" << endl;

cout << SS.size() << endl;
cout << SS[2] << endl;

swap(SS[0], SS[2]);
cout << SS[2] << endl;
}

ls2141 2010-07-24
  • 打赏
  • 举报
回复
数组越界了吧

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧