d2jsp
d2jsp Forums > Programmer's Haven > C/C++/C# > Reading From A File > Pretty Basic Except The Arithmetic
Add Reply New Topic New Poll
Cocoo
#1 Nov 24 2017 12:48pm
Group: Member
Posts: 20,707
Joined: Aug 3 2011
Gold: 1,699.00
File contains:

AAA+BCDEF (converting to hexadecimal first)
But the issue I have is with the actual addition function. I get 0 output from the console, not even 0. I'm not sure how to read the file "AAA+BCDEF". Thought the ifstream would pass it but now I'm just confused. Help?
Code


void addHex(ifstream inFile)
{
char ch;
long int num1 = 0;
long int num2 = 0;

inFile << ToHexdecimal(num1) << ToHexdecimal(num2);
ToHexdecimal(num1) + ToHexdecimal(num2);

}


string ToHexdecimal(long int decimalNum)
{
long int result;
int tempVal;

stack <char> hexDecimal;
string hexString;
stringstream concat;

result = decimalNum;

while (result != 0)
{
tempVal = result % 16;

if (tempVal < 10)
{
tempVal += 48;
}
else
{
tempVal += 55;
}

hexDecimal.push(tempVal);
result /= 16;
}
while (!hexDecimal.empty())
{
concat << hexDecimal.top();
hexString = concat.str();
hexDecimal.pop();
}
return hexString;
}
Go Back To C/C++/C# Topic List
Add Reply New Topic New Poll