gpt4 book ai didi

C++,windows->linux移植,mapfile问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:09:41 26 4
gpt4 key购买 nike

我正在将一个小型 C++ 控制台应用程序从 Windows 移植到 Linux GCC 4.3.2。编译时出现无法解决的奇怪错误。

Labels.cpp: In function ‘void DumpSymbols()’:
Labels.cpp:68: error: invalid conversion from ‘int’ to ‘std::_Ios_Openmode’
Labels.cpp:68: error: initializing argument 2 of ‘std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]’

标签.cpp:

#include <string>
#include <fstream>
#include <iostream>
#include "stdafx.h"
using namespace std;

#include "Opcodes.h"
#include "Labels.h"


Label LABELS[1024];
int labelcounter = 0;
int OffsetCounter = 0;

void AddLabel(string name, int line)
{
LABELS[labelcounter].name = name;
LABELS[labelcounter].line = line;
LABELS[labelcounter].offset = OffsetCounter;
printf("Adding label: %s[0x%X]\n", name.c_str(), OffsetCounter);
labelcounter++;
}

bool IsLabel(string name)
{
for(int i=0;i<labelcounter;i++)
{
if (LABELS[i].name.compare(name) == 0)
{
return true;
}
}
return false;
}

int GetOffset(string lbl)
{
for(int i=0;i<labelcounter;i++)
{
if (LABELS[i].name.compare(lbl) == 0)
{
printf("Refers to label '%s':0x%X\n", lbl.c_str(), LABELS[i].offset);
return LABELS[i].offset;
}
}
return -1;
}

void DumpSymbols()
{
ofstream mapfile("symbols.map", ios::out|ios::beg); //this line causes error

//mapfile.write(
char numbuf1[32];
itoa(labelcounter, numbuf1, 10);
mapfile.write((string(numbuf1) + "\n").c_str(), strlen(numbuf1)+1);

for(int i=0;i<labelcounter;i++)
{
string dump;
char numbuf[32];
itoa(LABELS[i].offset, numbuf, 10);
dump = string(LABELS[i].name) + "\t" + string(numbuf) + "\n";
mapfile.write(dump.c_str(), strlen(dump.c_str()));
}
}

stdafx.h:

#pragma once
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdlib>

谢谢。

最佳答案

只需删除“|ios::beg”:

ofstream mapfile("symbols.map", ios::out);

类型为ios_base::seekdir,不是打开方式;这是为了寻求一个位置。无论如何,您都会自动回到开头。

关于C++,windows->linux移植,mapfile问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/477787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com