parsing text using getline
I've got this code which parses a text file by reading through and assigning each individual string to a variable (an element in the 'holder' array). It is based mostly off of some code I found on youtube for reading text files on the newboston.com channel.
How could I assign an entire line to a variable as I read a text file?
I know that I need to use getline, but I can't figure out how to get it to work. Never programmed in C++ before, nor have I programmed much in general.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string holder[200];
int i = 0;
char filename[50];
char word[50];
ifstream inputobject;
cout << "filename equals: ";
cin.getline(filename, 50);
inputobject.open(filename);
inputobject >> word;
holder[i] = word;
while(inputobject.good()){
holder[i] = word;
inputobject >> word;
i++;
}
system("pause");
return 0;
}