Reading from a text file with stdin
Hello, my project asks that I read input from stdin that allows redirection from a text file. Then redirect the output to a different file using stdout . It mentions that can't use file operations to read the input. The text file I have is an 9x9 array of characters separated by spaces. I already set up a code that will convert it to a 2D array. But I'm not sure how to do the input/output correctly, currently I am using ifstream for reading the file.
(Sorry for the mess of a code)
Code:
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <array>
using namespace std;
int main()
{
//Open text file
ifstream file("letters.txt");
string line;
int row = 0;
int col;
char array[25][25];
// Insert each character into array
while (getline(file, line))
{
istringstream iss(line);
char value;
col = 0;
while (iss >> value)
{
array[row][col] = value ;
col++;
}
row++;
}
cout << "********PRINT OUTPUT******" << endl;
for (int i = 0; i < row; ++i)
{
for (int j = 0; j < col; ++j)
{
cout << array[i][j] << ' ';
}
cout << endl;
}
}