So if i have a program that takes stdin such as
1
5
2
4
How exactly can i go through each line and say print that value, This is what im thinking:
#include <iostream>
using namespace std;
int main()
{
while ( // input has ended// ) {
cout << //current line//
//increment to next line//
}
return 0;
}
Is there such a way or no?
The pattern that I like is:
As in the other answers, you can type
CTRL+Zto send anEOFtoSTDIN. IfSTDINis a pipe, thenEOFwill be sent when the stream has no more data.To save into a vector:
If you want a C-style array (although I would recommend
std::vector: