这是我编写的用于创建 sic/xe .asm 文件的符号表的代码....
#include<iostream>
#include<fstream>
#include<iomanip>
#include"aviasm.h"
using namespace std;
void aviasm::crsymtab()
{
ofstream outs("symtab.txt",ios::out);//creating the symtab
ofstream outi("intermfile.txt",ios::out);//creating the intermediate file
ifstream in("asmfile.txt",ios::in);//opening the asmfile which i have already written
in.seekg(0,ios::beg);
char c;
string str[3];
string subset;
long locctr=0;
int i=0;
while((c=in.get())!=EOF)
{
in.putback(c);
while((c=in.get())!='\n')
{
in.putback(c); //putting back the first encountered letter
in>>str[i++]; //the asm file has three or less fields in every row
}
if(str[0].size()!=0 && str[1].size()!=0 && str[2].size()!=0)//if all 3 are there
{
if(str[1]=="start")
{
outi<<hex<<locctr;
outs<<str[1]<<" "<<locctr<<"\n";
outs<<resetiosflags(ios::hex);
outi<<" "<<str[0]<<" "<<str[1]<<" "<<str[2]<<"\n";
locctr=stol(str[2],0,16);
}//str[1]=start
}//end of all the three fields
}
in.close();
outi.close();
outs.close();
}//end of crsymtab
.....这是一个示例sic/xe .asm 文件.....请注意,在上面的代码中,我没有包含整个编码,因为即使我注释掉除上面...发生的问题是每当我运行代码时:
出现一个消息框:
'Unhandled exception at 0x00ba7046 in aviasm.exe: 0xC0000005: Access violation writing location 0xcccccccc.'
出现,我的程序进入
调试模式......还有一个名为的文件出现在以下函数iosfwd(std::char_traits<char>)
的行中,带有一个箭头 :_Left=_Right;
static void __CLRCALL_OR_CDECL assign(_Elem& _Left, const _Elem& _Right) { // assign an element _Left = _Right; }
此外,我在块的开头和结尾向控制台输出了几句话,
str[1]="start"
以检查此功能是否正常工作......虽然两行都在
工作,而且我也确信程序从 asm 中成功获取了输入文件(我已经检查过了),没有行被输出到 intermfile 和 symtab ......请帮助?