0

I try to read data from a text file. The .get function of the istream reads a 5 in the txt-File but returns the corresponding ascii dec value which is 53. I want to convert that value to 5.

One line of the text file is formatted like that:

Format: [Text] = [Value]

Ex.: Config Value = 5

.

The code that is reading from the text file is:

tmpTxt.ignore(100, '='); //skips past the =
tmpTxt.ignore(100, ' '); //skips past the space
ConfigVec.push_back(tmpTxt.get()); //reads value and pushes it back to the vector(I want this value to be 5)
Atexoy
  • 11
  • 3
  • And what's stopping you from doing it? Finding an ascii-table should be easy, figuring out how to convert an ascii-code to the numeric value should be easy to. Please add some more details to describe the problems you've encoutered. – Lukas-T Oct 20 '20 at 11:11
  • I already tried the common methods of converting chars to int like casting and that stuff. I think that it is odd to copy the whole ascii table and hardcode it into the code... – Atexoy Oct 20 '20 at 11:14
  • So you want something like `atoi` (https://en.cppreference.com/w/cpp/string/byte/atoi) except that it natively works with single chars? – Sebastian Hoffmann Oct 20 '20 at 11:45
  • Yeahh, exactly that. Thanks – Atexoy Oct 20 '20 at 12:30

0 Answers0