I have a homework assignment and using strings is forbidden so I need to use char[] arays. My problem involves reading the first 150 characters (or until the end of the line, if it contains less than 150 characters) for every line in a text file. However, the function getline() gives the content of the line to a string, not a char[] array. I lookep up the internet and couldn't find a function, the parameter of which is an array. I tried:
fstream myFile;
myFile.open("message.txt", fstream::in);
char buffer[150];
while (!myFile.eof())
{
while (myFile.get(buffer, 150, '\n'))
{
cout << buffer;
}
}
myFile.close();
which gets one line but overall doesn't seem to work. Any ideas?