Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

: C++: I need a way to output a text file into a program. The text file contains formatting such as empty lines between paragraphs. I tried using ifstream and getline but this outputs all the text in one line. Help me please?

OpenStudy (anonymous):

It's possible there are line ending problems. I don't know C++ well, but getline might be looking for one kind of line ending, but your file has another kind. Unix: \r (I think it's 0x0D) Windows: \r\n (I think it's 0x0D0A) So, maybe if you're on Windows and the file uses Unix line endings getline will be looking for those 0x0A bytes and not find them, so it'll think the whole file is one line. This is just a theory.

OpenStudy (rsmith6559):

Unix uses linefeeds: \n 0x0a Macs use carriage returns: \r 0x0d Windows uses carriage returns/linefeeds: \r\n 0x0d0a Both of those functions talk about inputting the data into a string. A "raw" input, using get() into a vector of character might be a better option.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!