I'm doing a c++ program to display email header from a file "input.txt" where header is stored.I want to show From, To, Date and Subject. I searched on google and I found the following program program.I've understood most of the program but I didn't understand few lines. I want to know why they have taken string array -
string temp1[2]; //line number 11
Also I didn't understand following statement:
while(file>>temp1[i]) //line number 15
What is the use of >> operator here?
Also why didn't they increment i ?
Please help me understand this. Thank You.
PROGRAM:
#include <iostream>
#include"fstream"
using namespace std;
Looks line no reason at all. Maybe early decigion which got reworked later. A single string would work too.
Also I didn't understand following statement:
while(file>>temp1[i]) //line number 15
What is the use of >> operator here?
Extraction from stream, like cin >> something. That operator returns reference to stream operated upon, so you could chain calls. Another feature of streams is that you can convert them to boolean value to check if error occured in previous I/O operation. So this line whould be read as "while we succesfully read next string from file".
Also why didn't they increment i ?
There is no need. A single string instead of array would work just as fine: we only use it as temporary storage.