I've bene banging my head against a brick wall trying to work out how to do this.
I need to be able to read a text file line by line and to read each character of the line. When the character is a space, anything up to that is added to an array. Any other characters such as brackets are put into their own array element so i could have words and punctuation.
I haven't got very far as I can't find anything online so help me progress
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char ch;
ifstream myFile("textfile.txt");
if (! myFile)
{
cout << "Error opening output fle" << endl;
return -1;
}
while (! myFile.eof())
{
myFile.get(ch);
/*
This is where the adding to arrays/vectors would happen
*/
}
myFile.close();
return 0;
}
Can anyone please get me started?