usingnamespace std;
ifstream infile;
int main(int argc, char* argv[])
{
infile.open("linedata");
int numb_char=0;
char letter;
while(!infile.eof())
{
infile.get(letter);
cout << letter;
numb_char++;
break;
}
cout << " the number of characters is :" << numb_char << endl;
infile.close();
return 0;
}
why is not getting right data
g++ line3.cpp
./a.out a <linedata
t the number of characters is :1
//for some reason is getting the t of ./a.out why is not getting "a"
input
linedata is:
this is just an example of many A aa Aa
it suppose to be
a the number of characters is:6
thanks
You are passing as 'a' as a parameter, and redirecting the standard input to the file linedata. However your program does not use its parameters, and does not read from standard input.
1 2
while( not infile.eof() ){
infile.get(letter);
You don't reach eof until you try to read it. So it will be too late.
Change it to while( infile.get(letter) ){