找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1730|回复: 5

编译不提示出错,运行出现abnormal program termintion .

[复制链接]
发表于 2009-11-2 02:51:53 | 显示全部楼层 |阅读模式 IP:江苏扬州
编译不提示出错,运行出现abnormal program termintion .
原程序如下
// cf.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "cf.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strTemp;
CFile mFile;
cout <<"1sd";
if(mFile.Open("d:\\1.txt",CFile::modeRead)==0)
{
cout <<"sd";
return 0;
}

CArchive ar(&mFile,CArchive::load);
ar >> strTemp;//本语句处 出错,但编译不出错。
cout << "22";//本语句未能正常输出

ar.Close();
mFile.Close();
cout << strTemp;
}
return nRetCode;
}
发表于 2009-11-2 02:51:55 | 显示全部楼层 IP:江苏扬州
这 属于什么编程 啊,mfc吧 代码也太少了
要是用c++那就 建立控制台文件
回复

使用道具 举报

发表于 2009-11-2 02:51:57 | 显示全部楼层 IP:江苏扬州
if( ar.IsStoring() )//追加这个判断
ar >> strTemp;
//-------------------------------------------------------------------
以下是我改造后的序列存储,供参考
int saveTmp;
int fileLen;
char *pFileStr;
char strTemp[512];
CFile mFile;
cout <<"1sd";
if(!mFile.Open("D:\\1.txt",CFile::modeReadWrite,NULL))
{
cout <<"sd";
return;
}
fileLen = mFile.GetLength();
pFileStr = new char[fileLen];
mFile.Read(pFileStr, fileLen);
CArchive ar(&mFile,CArchive::load,512,strTemp);
ar.WriteString(pFileStr);
if( ar.IsStoring() )
ar >> saveTmp;
cout << "22";

ar.Close();
mFile.Close();
cout << strTemp;
回复

使用道具 举报

发表于 2009-11-2 02:51:59 | 显示全部楼层 IP:江苏扬州
名人能给我解释一个么,谢谢了
回复

使用道具 举报

发表于 2009-11-2 02:52:00 | 显示全部楼层 IP:江苏扬州
if(!mFile.Open("D:\\1.txt",CFile::modeReadWrite,NULL))
{
cout <<"sd";
return;
}
打开文件这个不用说了

fileLen = mFile.GetLength();
pFileStr = new char[fileLen];
取得文件的长度并且对数组初始化

ar.IsStoring()
判断存档文件是否存在

ar.WriteString(pFileStr);
序列化保存
mFile.Read(pFileStr, fileLen);
读取fileLen长的文件保存到pFileStr
回复

使用道具 举报

发表于 2009-11-2 02:52:02 | 显示全部楼层 IP:江苏扬州
谢谢名人
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 23:26 , Processed in 0.205037 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表