I am trying to read a file with a list of titles and authors, and I need to be able to ignore the newline character that separates each line in the file.
For example, my .txt file might have a list like this:
The Selfish Gene
Richard Dawkins
A Brave New World
Aldous Huxley
The Sun Also Rises
Ernest Hemingway
I have to use parallel arrays to store this info, and then be able to format the data like so:
The Selfish Gene (Richard Dawkins)
I was trying to use getline to read the data, but when I go to format the title and author, I get this:
The Selfish Gene
(Richard Dawkins
)
How do I ignore the newline character when I read in the list from the file?
This is what I have so far:
Sorry, I didn't mean to format that list with the blank lines between the authors and titles. I did that because that's how you do it in Stackoverflow.
It was supposed to just be: The Selfish Gene
Richard Dawkins
A Brave New World
Aldous Huxley
The Sun Also Rises
Ernest Hemingway
THANK YOU SO MUCH SLOPPY9!!! I realized my problem. The .txt file my instructor gave us was corrupt, or in some funny format, or having problems from his Windows machine to my Mac, or something. I copy and pasted the exact list of titles and authors into a new .txt file on my machine, and wa lah! It works like a charm!