ways to take input from STDIN until eof

hii,
Kindly tell me some cool methods of taking input from stdin until I get an eof as input for both c and c++ …its good to learn new things …:slight_smile:

Hello,

I do like this:

int main()
{
long long int M;
while(scanf("%lld", &M)!= EOF)
{
   // do stuff here
}
return 0;
} 

I used it, for example, for medium problem, Bytelandian Gold Coins :slight_smile:

Best regards,

Bruno

1 Like

In C++ it is even simpler

int main() {
    int x;
    while (cin >> x) {
        // do stuff
    }
    return 0;
}
1 Like

okkk!!! I used like this :-

string line;
while(getline(cin,line))
{
//do the stuff here by parsing the string
}

but it seems there is some space problem in it i.e it take a line then executes endl .
kindly clearify …???