Read in an Octal number from a text file using C++
I'm new to LinuxQuestions.org so please forgive me if I use an inproper protocol.
My question is as follows: I am reading in a text file that contains a series of numbers like the following:
1
14
7
23
etc....
My program is working with Octal numbers for all counting purposes so in main I am using the following statement:
cout << setbase(8);
This allows the rest of my program to work great. However, in the list of numbers shown above, the 14 will be read in as 16. In other words, C++ will convert the integer to an octal. The problem is, 14 is already an octal. How do I keep it as and octal?
Option: Read it from the file as a string and convert the string to octal. How?
Option: Read it from the file directly in an octal integer. How? int means integer (base 10). Is there an octal data-type in C++?
In short, I want my text file 14 to be read in as a 14 base 8 and not get converted.
Any help will be greatly appreciated.
pjordan
|