std::string example;
int fd = open(argv[1], O_RDONLY); //open file on file descriptor
int newfd = dup2(fd, 0);
//do stuff with file one then open file two
std::cin >> example;
std::cout << example << std:endl;
int fd2 = open(argv[2], O_RDONLY); //open file2 on file descriptor
int newfd2 = dup2(fd2, 0);
std::cin >> example;
std::cout << example << std:endl;
I've been looking for a solution to this for a while. Is there any way to open another file redirecting to stdin
? This is assuming argv[1]
, argv[2]
are files.
File1: abcdefg
File2: ABCDEFG
Expected Output:
abcdefg
ABCDEFG
Current Output:
abcdefg