I have the following .txt file:
test.txt
1,2,5,6
Passing into a small C++ program I made through command line as follows:
./test test.txt
Source is as follows:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
int temp =0;
ifstream file;
file.open(argv[1]);
while(!file.eof())
{
temp=file.get();
file.ignore(1,',');
cout<<temp<<' ';
}
return 0;
}
For some reason my output is not 1 2 5 6
but 49 50 53 54
. What gives?
UPDATE:
Also, I noticed there is another implementation of get()
. If I define char temp
then I can do file.get(temp)
and that will also save me converting ASCII representation. However I like using while (file >> temp)
so I will be going with that. Thanks.