I am trying to write some tool for MSDOS environment but it doesn't work as expected.
I want to get the tool to read from some commandline pipe, like
C:\> type a.txt|testpipe
where testpipe.exe is the compiled program.
The problem: After going through the piped contents, it does not stop at the CIN prompt marked in red. It just skips the reading but outputs all the prompts. Do I need to do something to fix the input after the pipe so it reads from the terminal?
#include<iostream>
#include<string>
using namespace std;
int main(int argc,char*argv[])
{
char a[100];
string b;
while(cin.getline(a,100))
{
// TYPING OUT THE PIPED CONTENTS TWICE
b=string(a);
cout<<a<<"\n";
cout<<b.c_str()<<"\n";
}
// SHOWING THE STATES B4 CLEARING ERRORS
cout<<"RDstate function: "<<cin.rdstate()<<endl;
cout<<" EOF function: "<<cin.eof()<<endl;
cout<<" FAIL function: "<<cin.fail()<<endl;
cout<<" BAD function: "<<cin.bad()<<endl;
cout<<" GOOD function: "<<cin.good()<<endl;
cin.clear();
cin.ignore(0,-1);
// SHOWING THE STATES AFTER CLEARING ERRORS
cout<<"RDstate function: "<<cin.rdstate()<<endl;
cout<<" EOF function: "<<cin.eof()<<endl;
cout<<" FAIL function: "<<cin.fail()<<endl;
cout<<" BAD function: "<<cin.bad()<<endl;
cout<<" GOOD function: "<<cin.good()<<endl;
// READ FROM TERMINAL INPUT
cout<<endl<<"Please enter something to test terminal input:"<<endl;
cout<<"RDstate function: "<<cin.rdstate()<<endl;
cout<<" EOF function: "<<cin.eof()<<endl;
cout<<" FAIL function: "<<cin.fail()<<endl;
cout<<" BAD function: "<<cin.bad()<<endl;
cout<<" GOOD function: "<<cin.good()<<endl;
cin.getline(a,100);
b=a;
cout<<"Input:\t"<<a<<endl;
cout<<"Input(string):\t"<<b.c_str();
return 0;
}