I am trying to read the file using getline() function and piping my input file using bash command but get illogical output.
This is my main.cpp code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
string line;
while(getline(cin,line)){
cout<<line<<endl;
}
return 0;
}
My input file named input.txt look like this
4 MF MF FM FF MF MM
MM FF
MF MF MF MF FF
My bash command and running result
DENGs-MacBook-Pro:APS stevedeng$ g++ -o main main.cpp -std=c++11
DENGs-MacBook-Pro:APS stevedeng$ ./main < input.txt
MF MF MF MF FFMF MM
What I thought is that the program will read the input.txt line by line and print the output exactly as the format as the input file.
Can someone explain what is happening here with the only one line of wired looking output?
How can I achieve the result of reading it line by line if the only way I can do is piping the input file from bash instead of using ifstream? Any help will be appreciated.