| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 839 人关注过本帖
标题:编译不提示出错,运行出现abnormal program termintion .
只看楼主 加入收藏
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
结帖率:33.33%
收藏
 问题点数:0 回复次数:5 
编译不提示出错,运行出现abnormal program termintion .

编译不提示出错,运行出现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;
}

搜索更多相关主题的帖子: program abnormal termintion 编译 运行 
2006-03-06 09:38
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
收藏
得分:0 

这 属于什么编程 啊,mfc吧 代码也太少了
要是用c++那就 建立控制台文件


http://kongfuziandlife. http://codeanddesign.
2006-03-06 11:25
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 
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;

未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-06 11:51
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 

名人能给我解释一个么,谢谢了


长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2006-03-07 14:37
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 
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

未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-07 14:58
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 

谢谢名人


长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2006-03-08 09:26
快速回复:编译不提示出错,运行出现abnormal program termintion .
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018680 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved