I'm trying to take input from a file and convert it into variables. I want each line of the file (including whitespace) to get stored as a string in its own variable. Right now I have
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout << "Please enter the file name: " << endl;
string filename;
cin >> filename;
ifstream f (filename);
if(f.is_open())
{
string line1;
string line2;
string line3;
string line4;
f >> line1 >> line2 >> line3 >> line4;
}
else
cout << "Invalid File Name" << endl;
return 0;
}
The issue being if line 1 is "John Doe" it'll make line1 variable be "John" and line2 be "Doe".
I know I should use getline somehow, but I don't exactly understand how. I tried getline(f, line1 >> line2 etc but it didn't like that lol