Hi I want to how can we take input from stdin again after I invoke:
freopen("Smefile.txt","r",stdin);
Precisely I want my first in first of my program should take input from a designated file the next part would take from the stdin.
Like:
int a,b;
freopen("Smefile.txt","r",stdin);
scanf("%d",&a);
{
//some block here such that the next cin/scanf takes b from standard input
}
cin>> b;
cout <<a<<" "<<b;
Any ideas?
You can’t. Use
instead.
This won’t help when you’re mixing C++ and C-style I/O on the same stream, which I wouldn’t recommend anyway.
(If you happen to be on Linux, you can reopen
/dev/stdininstead. On Linux/Unix, you can also use Jerry Coffin’sdup2trick, but that’s even hairier.)