For faster input, I read that you can do file-redirection
and include a file with the cin
inputs already set.
In theory it should be used l
[I am just explaining the command line argument used in Question]
You can provide file name as command line input to the executible, but then you need to open them in your code.
Like
You have supplied two command line arguments namely inputfile & outputfile
[ App.exe inputfile outputfile
]
Now in your code
#include
#include
#include
int main(int argc, char * argv[])
{
//argv[0] := A.exe
//argv[1] := inputFile
//argv[2] := outputFile
std::ifstream vInFile(argv[1],std::ios::in);
// notice I have given first command line argument as file name
std::ofstream vOutFile(argv[2],std::ios::out | std::ios::app);
// notice I have given second command line argument as file name
if (vInFile.is_open())
{
std::string line;
getline (vInFile,line); //Fixing it as per the comment made by MSalters
while ( vInFile.good() )
{
vOutFile << line << std::endl;
getline (vInFile,line);
}
vInFile.close();
vOutFile.close();
}
else std::cout << "Unable to open file";
return 0;
}