I'm struggling to find a way to both read a file to the end of a line, such as
dog \n cat \n pig
and store the char of each to an array. While I can do this for one line, I can't work out how to move on to the next line (ie dog to cat) and still register the end of the file. Here is my code so far;
searchFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
char next;
while (searchFile.get(next))
{
if (next == '\n') // If the file has been opened in
{
for (int i = 0; i <= searchTempSize; i++) // ... For each character within the total length of the string ...
{
searchCharArray[i] = searchArray[i];
cout << searchCharArray[i] << endl;
}
}
}
Edit for clarity: I need to read the file and store the characters of each word as an array. However, the file contains each word on a new line. I can't seem to find a way to read on to the next line, rather than end.