Hello. I'm porting a small C++ console application from windows to linux, GCC 4.3.2. When compiling I get strange error that I'm unable to solve.
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>]’
Labels.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>
Thanks.