How can you read from a file a line of words (sentence) using c-strings? Let's say you have a character array and then inside a text file is a group of sentences:
I like playing video games.
I love programming.
C++ is awesome!
I'm trying to read from the file and insert each of the sentences inside a character array. How would you go about doing that?
Thanks for the reply! But I've already used getline before. I was just wondering if there is a way to input a group of words (with spaces) into a c-string. Would you have to concatenate each individual word or string?
Well, it depends on your input: If you have a file with words delimited by spaces, and several words on each line, it makes sense to read them in as an entire line. The getline() function does just that. You should use a standard container instead of character arrays: They are much easier and automatically allocate the memory needed for your data: