Char to Integer coversion in c++
I am trying to convert a Char to Int in my c++ program,followed some of
the answers from this site but its still not working . I have a input file
with following data in file ld.txt
4
8 2
5 6
8 2
2 3
./LD
int main()
{
using namespace std;
std::vector<int> nums;
int i,k;
char j;
for(i=0;;i++)
{
j=fgetc(stdin);
int l =j - 48;
if(feof(stdin))
break;
nums.push_back(l);
cout<<nums[i]<<endl;
}
}
O/p- 4 -38 8 -16 2 -38 5 -16 6 -38 8 -16 2 -38 2 -16 3 -38
Not sure why i am getting the -ve numbers
No comments:
Post a Comment