I'm trying to get each line of text of a file split into words and then put into an array
I found an exmaple oc cpluscplus.com and their example works but when i try to edit to make changes to read the line of text from a file i get an error on this line:
char str[] = getline(filename, line);
error message:
error c2440: 'initializing' : cannot convert from 'std::basic_istream<_Elem,_Traits>' to 'char[]'
I need to be able to read in a line and spilt the words into an array so i can output them
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
string GetFileName;
cout << "System >> Enter file to read: \n";
cout << "User >> ";
cin >> GetFileName;
ifstream filename( GetFileName.c_str() );
if(! filename )
{
cout << "Unable to open file: " << GetFileName << endl;
return EXIT_FAILURE;
}
else
{
while (getline(filename, line)) //Loop through lines
{
char str[] = getline(filename, line);
char * pch;
pch = strtok (str," ");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ");
}
}
filename.close();
}
return EXIT_SUCCESS;
}